Skip to content

Package development

morota edited this page Dec 20, 2012 · 5 revisions

Steps to build a package.

R CMD build packageName
R CMD check --as-cran mypackageName_x.y-z.tar.gz
R CMD INSTALL packageName_x.y-z.tar.gz

R CMD build --help
R CMD check --help
R CMD INSTALL --help
  • Use R CMD INSTALL --with-keep.source or set environment variable R_KEEP_PKG_SOURCE=yes to keep sources.

Submission to CRAN

Try Win-builder for building and checking R source packages for Windows.

Upload a package to CRAN. name:anonymous, pass:my.email.adreess.

ncftp ftp://cran.r-project.org/incoming

NAMESPACE

  • Definitely check out Luke Tierney's article in R news "Volume 3/1 June 2003, Name Space Management for R"
  • When import namespaces in a NAMESPACE, make sure to add it to Imports section in DESCRIPTION.

DESCRIPTION

  • Use LazyData in DESCRIPTION file instead of data(), to avoid "R CMD check returns NOTE about package data set as global variable"

.RD file

After you modified a .Rd file, you can check the changed .Rd file before installing by

R CMD Rdconv --type=txt snpgrid.Rd
R CMD Rd2pdf pkg-name 

Use tools::checkRd to check Rd files from within R.

codetools:::checkUsage
setwd("~/dkDNA/man")
filenames <- list.files(pattern="[.]Rd$");
sapply(filenames, FUN=tools::checkRd)

When you add new functions to existing packages, source() them, and generate *.Rd files using prompt().

Examples in .Rd files

If example codes fail, check out foo.Rcheck/foo-Ex.R by running:

R --vanilla < foo-Ex.R
env LANGUAGE=en R --vanilla --encoding=latin1 < foo-Ex.R

Bytecompile

ByteCompile to 'yes' transforms R code into byte-code (requires lazy-loading). The R interpreter can execute this byte-code more quickly than R code. Byte compilation is expensive and takes more time to install packages. It is said that only very few packages benefit considerably from byte-compilation and many packages benefit from byte-compilation of R itself.

Definition

R CMD INSTALL is defined in:

src/library/tools/R/install.R

R CMD BUILD is defined in:

src/library/tools/R/build.R

Sweave

Put *.Rnw to vignettes/. To put non-Sweave prebuilt pdf check this page.

useful functions

?match.call
?hasArg
?missing
?exists
?loadedNamespaces
stopifnot(packageVersion("foo") == "3.14") 
stopifnot(compareVersion(packageVersion("foo"), "3.14") < 0)

Misc

  • inst/ directory will be removed once the package is intalled.
  • Do not include STOP function in fortran
  • Use .Rbuildignore so that R CMD build ignores some directories
  • How To Make an R Package Based on C++

Clone this wiki locally