HenrikBengtsson / startup

:wrench: R package: startup - Friendly R Startup Configuration
https://henrikbengtsson.github.io/startup/
163 stars 5 forks source link

R CMD check hooks? #46

Open HenrikBengtsson opened 6 years ago

HenrikBengtsson commented 6 years ago

Is it possible to detect/infer, during .Rprofile, whether R CMD check is running or not? (I'd expect commandArgs() would reflect this)

If so, we could add an element to startup::sysinfo() that reflects this, e.g. string r_cmd taking values build, INSTALL, and check.

And then, one could add a "hook" that reports on more information about the R session that what R CMD check reports on, e.g. what environment variables, locales, R options, .libPaths() etc. R CMD check sees. This info could be outputted to a log file in the check directory but possibly also be outputted to the terminal (unless R CMD ... redirects all that).

HenrikBengtsson commented 6 years ago

To detect various R CMD <command> calls, see https://github.com/wch/r-source/blob/trunk/src/scripts/, e.g.

HenrikBengtsson commented 6 years ago

Don't forget R.utils::queryRCmdCheck() which does something similar.

HenrikBengtsson commented 4 years ago

Adding

utils::str(list(
  cmdargs = commandArgs(),
  R_CMD = Sys.getenv("R_CMD")
), vec.len = +Inf)

to ~/.Rprofile reveals that calls to R CMD build ..., R CMD check ... and R CMD INSTALL ... carry the following information:

On Windows:

C:\Users\hb> R CMD build --help
List of 2
 $ cmdargs: chr [1:9] "C:\\PROGRA~1\\R\\R-36~1.3/bin/x64/Rterm.exe" "-e" "tools:::.build_packages()" "R_DEFAULT_PACKAGES=" "LC_COLLATE=C" "--no-restore" "--slave" "--args" "nextArg--help"
 $ R_CMD  : chr "R CMD"
 $ stdin  : chr [1:2] "tools:::.build_packages()" ""

C:\Users\hb> R CMD check --help
List of 2
 $ cmdargs: chr [1:9] "C:\\PROGRA~1\\R\\R-36~1.3/bin/x64/Rterm.exe" "-e" "tools:::.check_packages()" "R_DEFAULT_PACKAGES=" "LC_COLLATE=C" "--no-restore" "--slave" "--args" "nextArg--help"
 $ R_CMD  : chr "R CMD"
 $ stdin  : chr [1:2] "tools:::.check_packages()" ""

C:\Users\hb>R CMD INSTALL --help
List of 3
 $ cmdargs: chr [1:9] "C:\\PROGRA~1\\R\\R-36~1.3/bin/x64/Rterm.exe" "-e" "tools:::.install_packages()" "R_DEFAULT_PACKAGES=" "LC_COLLATE=C" "--no-restore" "--slave" "--args" "nextArg--help"
 $ R_CMD  : chr "R CMD"
 $ stdin  : chr [1:2] "tools:::.install_packages()" ""

On Linux:

$ R CMD build --help
List of 2
 $ cmdargs: chr [1:5] "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/exec/R" "--no-restore" "--no-echo" "--args" "nextArg--help"
 $ R_CMD  : chr "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/Rcmd"
 $ stdin  : chr "tools:::.build_packages()"

$ R CMD check --help
List of 2
 $ cmdargs: chr [1:5] "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/exec/R" "--no-restore" "--no-echo" "--args" "nextArg--help"
 $ R_CMD  : chr "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/Rcmd"
 $ stdin  : chr "tools:::.check_packages()"

$ R CMD INSTALL --help
List of 3
 $ cmdargs: chr [1:5] "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/exec/R" "--no-restore" "--no-echo" "--args" "nextArg--help"
 $ R_CMD  : chr "/home/hb/software/R-devel/R-4-0-branch/lib/R/bin/Rcmd"
 $ stdin  : chr "tools:::.install_packages()"