Perform an operating system command. For example, perform R CMD package commands directly from R.
  • command – A character string of a command.

Example. The getwd and setwd commands are used to navigate to a folder containing the packageName package, which is the sample package created in the package building tutorial posted here. The list.files function was used to verify the packageName folder was in my current working directory. Then the package was installed from this source folder using the system function. A compressed tar.gz file (a.k.a. a tarball) for sharing or archiving the package was also created using the R CMD build command. The packageName_1.0.tar.gz file in the current working directory, shown in the second list of files but not in the first, was created by the R CMD build command.
> getwd()
[1] "/Users/ddiez"
> setwd("Dropbox/RFunction/code/1202")
> list.files()
[1] "120201.R"                  "120202.R"                 
[3] "120203-NotUsed.R"          "120203.R"                 
[5] "120204.R"                  "normTail.Rd"              
[7] "packageName"               "RFunctionFolderLayout.png"
> system("R CMD install packageName")
* installing to library ‘/Library/Frameworks/R.framework/Versions/
* installing *source* package ‘packageName’ ...
** R
** data
** preparing package for lazy loading
** help
*** installing help indices
** building package indices ...
** testing if installed package can be loaded

* DONE (packageName)
> system("R CMD build packageName")
* checking for file ‘packageName/DESCRIPTION’ ... OK
* preparing ‘packageName’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building ‘packageName_1.0.tar.gz’

> list.files()
[1] "120201.R"                  "120202.R"                 
[3] "120203-NotUsed.R"          "120203.R"                 
[5] "120204.R"                  "normTail.Rd"              
[7] "packageName"               "packageName_1.0.tar.gz"   
[9] "RFunctionFolderLayout.png"
Tip. If you are building packages and on a PC, be sure to install Rtools first. On a Mac? You may need to get Xcode (signing up as a developer is free). If you are running R CMD check, you may need to also install LaTeX (Mac, Windows).

Leave a Reply