Keep Source When Installing R Packages

Keep Source When Installing R Packages

When sourcing R functions from a file, the comments and indentation within the function body are kept and can be inspected in the console. Meanwhile, functions from installed packages, by default, are parsed to the standard format and all the comments are striped.

What I often do when playing a package is to inspect the functions in the console and see how they are implemented, and I always hope to see the author's inline comments if possible. For another aspect, some package authors may want to let his/her package to be installed keeping source by default, so that they can present their functions with inline comments and formatting to packages users.

Install with keeping source

For individual packages, just install with

install.packages(pkgname, INSTALL_opts = c("--with-keep.source"))


biocLite(pkgname, INSTALL_opts = c("--with-keep.source")))

In order to set it by default, put the following line in `.Rprofile`:

Sys.setenv(R_KEEP_PKG_SOURCE = "yes")

Set a package to be installed keeping source by default

Add a "KeepSource" logical field in DESCRIPTION file, like

KeepSource: true

In this way, when the package is installed by other users (from CRAN, Bioconductor, GitHub, etc.), the source (comments and formatting) will be kept by default.

The option can be traced back to a thread in R-devel mailing list and Prof Ripley provided the solution.

comments powered by Disqus