Raumzeitfalle.net
  • Photography
  • Augenblick.in
  • Sassily - Made With Love
  • Connys Blog - Rezepte & Tipps
  • RSS Feed
  • More...
    • Photo Blog
    • Github
    • JavaFX Example Project
    • Social Media
    • Twitter
    • AsciiDoc
    • Asciidoctor Syntax Quick Reference

Building packages for R on Windows: running the first build

02 Oktober 2017

This post shows how to execute the first build with the project structure created previously.

Step-by-Step

Befor starting the actual build, ensure that the R\bin folder, the RTools, RTools\bin, RTools\gcc folders are reachable from your command line.

If this is given, the build can be started with:

cd StatementR
R CMD build

Given the case, that the mentioned directories are not part of your %PATH% environment variable, it is suitable to create a make.cmd file. This is also the proposed way to run your builds as it enables you to have multiple versions of RTools and R in parallel. R CMD takes the package name as an argument (%1) and will look for a folder with this name. Therefor it will be helpful to place make.cmd in the workspace directory, so one level above the project in the workspace directory. Also when successfully compiled, the build artifacts (.tar.gz and .zip files) will be located in workspace.

@echo off
setlocal
set path=%path%;"C:\Program Files\R\R-3.3.2\bin\x64";
set path=%path%;C:\tools\Rtools33;C:\tools\Rtools33\bin;C:\tools\Rtools33\gcc-4.6.3;
set path=%path%;"C:\Program Files\MiKTeX 2.9\miktex\bin\x64";
R CMD build %1
endlocal

With having make.cmd created the project structure now looks as follows:

Package Structure

Lets run the build

cd workspace
make StatementR
* checking for file 'StatementR/DESCRIPTION' ... OK
* preparing 'StatementR':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
Removed empty directory 'StatementR/inst/extdata'
Removed empty directory 'StatementR/inst'
Removed empty directory 'StatementR/man'
* creating default NAMESPACE file
* building 'StatementR_0.1.tar.gz'

R CMD build StatementR produces a .tar.gz file, which cannot be installed easily in Windows. Here the INSTALL command must be run. INSTALL will create .zip file and try to install it locally. When the install fails, the package is revoked from local library. However, you must have the priviledges to write into the R runtime library folder. Here it can be helpful to run CMD with administrative priviledges.

Furthermore the R CHECK command allows to verify if the build was successfull. So adding the 2 lines R CMD check %1 and R CMD INSTALL --build %1 to make.cmd will enable automated build and test and deployment.

R CMD build StatementR
R CMD check StatementR
R CMD INSTALL --build StatementR

After having the process completed, the artifacts StatementR_0.1.tar.gz and StatementR_0.1.zip will be available in workspace directory. The newly created subfolder StatementR.Rcheck will contain log files and the manual file StatementR-manual.pdf.

Package Structure

The so created library can be loaded in R using the library statement. As defined in file NAMESPACE, the function saySomething is available and luckily returns something. Instead, function getRandomValue is not available as it was not exported.

library(StatementR)
saySomething()
[1] "These tree will be ugly ."

getRandomValue()
Error: could not find function "getRandomValue"

So, the first package was built. Unfortunately the documentation (PDF manual) is still empty as there were no .Rd files during build. Also creating NAMESPACE file can be painful for large projects. The next post will explain how to automate documentation and NAMESPACE file generation using roxygen2 package.


© 2014 | Mixed with Bootstrap v3.1.1 | Baked with JBake v2.6.0-SNAPSHOT