5

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.

I run :

library("devtools")
install("DESeq2", keep_source=TRUE)

It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.

QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.

R Yoda
  • 8,358
  • 2
  • 50
  • 87
irritable_phd_syndrome
  • 4,631
  • 3
  • 32
  • 60
  • I thought that `keep.source` was an instruction to include the source in the code that would be loaded, not to keep particular files in the `/library/..`. I'm also not sure how it would be expected to work with Rcpp code. I also think you may need to look at what is being passed to `type` since that is OS dependent and you haven't told us that bit of information. – IRTFM Feb 22 '18 at 19:25
  • Added Requested info. In `?install` it says : "keep_source: If ‘TRUE’ will keep the srcrefs from an installed package. This is useful for debugging (especially inside of RStudio). It defaults to the option ‘"keep.source.pkgs"’." I guess I was assuming that 'srcrefs' would include the source code? Maybe not? – irritable_phd_syndrome Feb 22 '18 at 19:30
  • What do you mean being passed to `type`? `type` isn't an argument for `install`. – irritable_phd_syndrome Feb 22 '18 at 19:36
  • I assumed it would get passed to `install.packages`. Perhaps not? – IRTFM Feb 22 '18 at 22:50
  • 1
    `keep_source=TRUE` will [simply pass](https://github.com/r-lib/devtools/blob/master/R/install.r#L146) `--with-keep.source` to [`rcmd`](https://www.rdocumentation.org/packages/callr/versions/1.0.0/topics/rcmd). [According to docs](https://stat.ethz.ch/R-manual/R-devel/library/utils/html/INSTALL.html), "Packages are not by default installed keeping the source formatting," this option enables that. – miken32 Feb 22 '18 at 23:07

1 Answers1

6

R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).

Even if

  • you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
  • and you have installed the package with the source code (like you did or via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))

you will not find R files in R folder there.

You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:

print(DeSeq2::any_function)

To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:

keep.source.pkgs:

As for keep.source, used only when packages are installed. Defaults to FALSE unless the environment variable R_KEEP_PKG_SOURCE is set to yes.

Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).

For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

R Yoda
  • 8,358
  • 2
  • 50
  • 87