[Rd] R CMD check --as-cran attempts to hide R_LIBS_USER but fails

Henrik Bengtsson henr|k@bengt@@on @end|ng |rom gm@||@com
Thu Mar 19 03:19:11 CET 2020

AFAIU, 'R CMD check --as-cran' tries to hide any site and user package
libraries by setting R_LIBS_SITE and R_LIBS_USER.  However, contrary
to R_LIBS_SITE, it fails for R_LIBS_USER and the user's personal
library is still available for test scripts.  Should I revise my
assumptions, or is that intentional?

The short version. Shouldn't:

$ R_LIBS_USER='' Rscript --vanilla -e ".libPaths()"
[1] "/home/hb/R/x86_64-pc-linux-gnu-library/4.0"
[2] "/home/hb/software/R-devel/trunk/lib/R/library"

give the same output as:

$ R_LIBS_USER="no_such_dir" Rscript --vanilla -e ".libPaths()"
[1] "/home/hb/software/R-devel/trunk/lib/R/library"


The long version:

R_LIBS_SITE='no_such_dir' and R_LIBS_USER=''  is set up at the very
end of tools:::setRlibs():

setRlibs <-
    c(paste0("R_LIBS=", rlibs),
      if(WINDOWS) " R_ENVIRON_USER='no_such_file'" else "R_ENVIRON_USER=''",
      if(WINDOWS) " R_LIBS_USER='no_such_dir'" else "R_LIBS_USER=''",
      " R_LIBS_SITE='no_such_dir'")

Monitoring with 'pstree' confirms this. On Linux with R 3.6.3, the
call stack of a 'R CMD check --as-cran teeny_0.1.0.tar.gz' call looks
like this when a test script is running:

`-sh /usr/lib/R/bin/check --as-cran teeny_0.1.0.tar.gz
 `-R --no-restore --slave --args nextArg--as-crannextArgteeny_0.1.0.tar.gz
R_LIBS=/tmp/hb/RtmpQj4hXb/RLIBS_26e766e32c18 R_ENVIRON_USER=''
R_LIBS_USER=''  R_LIBS_SITE='no_such_dir' '/usr/lib/R/bin/R' --vanilla
--slave < '/tmp/hb/RtmpQj4hXb/file26e763770b6a'
   `-R --vanilla --slave
    `-sh -c LANGUAGE=C R_TESTS=startup.Rs '/usr/lib/R/bin/R' CMD BATCH
--vanilla  'env.R' 'env.Rout'
     `-sh /usr/lib/R/bin/BATCH --vanilla env.R env.Rout
      `-R -f env.R --restore --save --no-readline --vanilla
       `-sh -c 'pstree' --arguments --long --show-parents 10558
        `-pstree --arguments --long --show-parents 10558

However, if I call print(Sys.getenv("R_LIBS_USER")) in my tests/env.R,
I'll find that it is no longer empty but it is indeed set to my
personal library "~/R/x86_64-pc-linux-gnu-library/3.6".


It looks like R_LIBS_USER is set if and only if it's empty by Renviron
in my system folder:

$ grep R_LIBS < "$(Rscript -e "cat(file.path(R.home('etc'), 'Renviron'))")"
# edd Jul 2007  Now use R_LIBS_SITE, not R_LIBS

This is from installing R on Ubuntu 18.04 using 'apt install
r-base-core'.  To make sure it's not an issue with that distribution,
I also check a 'configure/make/make install' from SVN trunk and there
I see the same:

$ grep R_LIBS < "$(Rscript -e "cat(file.path(R.home('etc'), 'Renviron'))")"

Printing it during tests/env.R confirms that it is indeed set to


More information about the R-devel mailing list