HenrikBengtsson / startup

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

Predefined startup configurations, e.g. emulate R CMD build #39

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

Triggered by discussion in Bioc-devel thread 'How to recreate R CMD BUILD environment in interactive session?' on 2017-10-23, I might be helpful if the startup package provides a way to emulate certain startup configuration such as:

For instance, from above Bioc-devel thread mention that R CMD build ends up running R as:

echo 'tools:::.build_packages()' | R_DEFAULT_PACKAGES= LC_COLLATE=C 
"${R_HOME}/bin/R" --no-restore --slave --args ${args}

Some ideas on the API for preset configs:

startup::startup(as = "R CMD build")

and

$ R_STARTUP_AS="R CMD build" R

with startup::startup() in .Rprofile.

Maybe one could relaunch an R session by:

> startup::restart(as = "R CMD build")

which will create a one-time Rprofile file containing startup::startup(as = "R CMD build") using R_PROFILE_USER or similar.

UPDATE 2017-10-26: It looks like the startup::restart() idea is sufficient.

HenrikBengtsson commented 6 years ago

Restarting R can be done using something like:

restart_r <- function(status = 0, debug = TRUE) {
  if (debug) message("restart_r(): Customizing .Last() to relaunch R ...")
  assign(".Last", function() {
    args <- commandArgs()
    system2(args[1], args = args[-1])
  }, envir = globalenv())   
  if (debug) message("restart_r(): Quitting current R session and starting a new one ...")
  quit(save = "no", status = status, runLast = TRUE)
}

Source: https://stackoverflow.com/a/43792584/1072091

Note also that RStudio has a .rs.restartR().