keep.source.pkgs vs. keep.source options

R's 'options' documentation mentions these two entries:

keep.source :

When TRUE , the source code for functions (newly defined or loaded) is stored internally allowing comments to be kept in the right places. Retrieve the source by printing or using deparse(fn, control = "useSource") .

The default is interactive() , i.e., TRUE for interactive use.

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 .

Reading through the Debugging with RStudio article, I noticed it does advise to build your packages --with-keep-source (and that this is the default for RStudio), but keep.source.pkgs is nowhere mentioned.

What is the right way to use this option? What does it add?

1 Like

What an interesting question! Disclaimer: I didn't know about the options before reading it. I suppose most often when debugging one's own package, one won't use the installed package for debugging, rather just the devtools::load_all() workflow, hence keep.source being more useful than keep.source.pkgs.

From your question and looking in the R source mirror, I saw one could use keep.source.pkgs to try and find the reason for a R CMD check NOTE, see these code lines

                        wrapLog("Information on the location(s)",
                                "of code generating the",
                                paste0(sQuote("Note"), "s"),
                                "can be obtained by re-running with",
                                "environment variable R_KEEP_PKG_SOURCE",
                                "set to 'yes'.\n")

I was also thinking that if one set the variable to 'yes' all the time (e.g. in .Renv), using lookup::lookup() locally might be a nicer experience than it is when reading the code without comment (edit: tested, I installed a package from source with the keep-source option install.packages("rhub", INSTALL_opts = "--with-keep.source") -- on source because it was on Ubuntu). On the other hand it makes the packages bigger, not sure how much it matters.

Further edit: I suppose the users only have the freedom to use --with-keep-source for installation if one builds the package with keep.source. :slightly_smiling_face: