HenrikBengtsson / startup

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

renv and startup #76

Closed pat-s closed 4 years ago

pat-s commented 4 years ago

When combining both, I get a false positive about

* Project '~/git/mlr-org/mlr3' loaded. [renv 0.8.2-19]
Warning message:
In check_rstudio_option_error_conflict(debug = debug) :
  startup::check(): CONFLICT: Option ‘error’ was set during the R startup, but this will be overridden by the RStudio settings (menu ‘Debug -> On Error’) when using the RStudio Console. To silence this warning, set option 'error' using ‘if (!startup::sysinfo()$rstudio) options(error = ...)’. For further details on this issue, see https://github.com/rstudio/rstudio/issues/300

I do not have any call to options(error = ) in my .Rprofile('s). Also RStudios "debug" is set to "message only". Also when not using renv everything is fine. Haven't yet checked if renv alters this option somehow.

startup::startup(debug = TRUE) with renv ```r > startup::startup(debug = T) 0.000s: System information: 0.001s: - R_HOME: ‘/usr/lib64/R’ (existing folder) 0.001s: - R call: RStudio --interactive 0.001s: - Current directory: ‘/home/pjs/git/mlr-org/mlr3’ 0.001s: - User's home directory: ‘~’ => ‘/home/pjs’ (existing folder) 0.002s: - Search path: ‘.GlobalEnv’, ‘tools:rstudio’, ‘package:stats’, ‘package:graphics’, ‘package:grDevices’, ‘package:utils’, ‘package:datasets’, ‘package:methods’, ‘Autoloads’, ‘package:base’ 0.002s: - Loaded namespaces: ‘compiler’, ‘startup’, ‘graphics’, ‘tools’, ‘utils’, ‘grDevices’, ‘stats’, ‘datasets’, ‘methods’, ‘packrat’, ‘base’ 0.002s: The following has already been processed by R: 0.002s: - R_ENVIRON: ‘’ 0.002s: - R_ENVIRON_USER: ‘’ 0.003s: - ‘/usr/lib64/R/etc/Renviron’ (22 lines; 1697 bytes) setting 22 environment variables (‘R_PLATFORM’, ‘R_PAPERSIZE_USER’, ‘R_PAPERSIZE’, ‘R_PRINTCMD’, ‘R_RD4PDF’, ‘R_TEXI2DVICMD’, ‘R_GZIPCMD’, ‘R_UNZIPCMD’, ‘R_ZIPCMD’, ‘R_BZIPCMD’, ‘R_BROWSER’, ‘EDITOR’, ‘PAGER’, ‘R_PDFVIEWER’, ‘LN_S’, ‘MAKE’, ‘SED’, ‘TAR’, ‘R_SYSTEM_ABI’, ‘R_STRIP_SHARED_LIB’, ‘R_STRIP_STATIC_LIB’, ‘R_LIBS_USER’) 0.003s: - ‘~/.Renviron’ => ‘/home/pjs/.Renviron’ (0 lines; 0 bytes) setting 0 environment variables 0.004s: - R_DEFAULT_PACKAGES: ‘’ (= ‘base,methods,datasets,utils,grDevices,graphics,stats’) 0.004s: - R_LIBS: ‘’ 0.004s: - R_LIBS_SITE: ‘’ 0.004s: - R_LIBS_USER: ‘~/R/x86_64-pc-linux-gnu-library/3.6’ 0.004s: - R_PROFILE: ‘’ 0.004s: - R_PROFILE_USER: ‘’ 0.005s: - ‘.Rprofile’ (0 code lines; 27 bytes) 0.005s: startup::startup()-specific processing ... 0.005s: Found startup directory ‘~/.Renviron.d’. 0.008s: Processing 2 Renviron files ... 0.008s: - ‘/home/pjs/.Renviron.d/Github_PAT.R’ (1 lines; 52 bytes) setting 1 environment variables (‘GITHUB_PAT’) 0.009s: - ‘/home/pjs/.Renviron.d/envs.R’ (2 lines; 159 bytes) setting 2 environment variables (‘_R_CHECK_LENGTH_1_CONDITION_’, ‘R_REMOTES_UPGRADE’) 0.009s: Processing 2 Renviron files ... done 0.011s: Found startup directory ‘~/.Rprofile.d’. 0.013s: Processing 5 Rprofile files ... 0.014s: - ‘/home/pjs/.Rprofile.d/repos.R’ (3 code lines; 223 bytes) 0.014s: - ‘/home/pjs/.Rprofile.d/rstudio-theme.R’ (11 code lines; 477 bytes) 0.083s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/load-at-start.R’ (2 code lines; 47 bytes) 0.214s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/load-at-start.R##hpc’ (1 code lines; 24 bytes) 0.214s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/options.R’ (32 code lines; 2150 bytes) 0.373s: Processing 5 Rprofile files ... done 0.374s: - unloading the ‘startup’ package 0.374s: - Search path: ‘.GlobalEnv’, ‘package:usethis’, ‘package:teamtools’, ‘tools:rstudio’, ‘package:stats’, ‘package:graphics’, ‘package:grDevices’, ‘package:utils’, ‘package:datasets’, ‘package:methods’, ‘Autoloads’, ‘package:base’ 0.374s: - Loaded namespaces: ‘Rcpp’, ‘grDevices’, ‘packrat’, ‘crayon’, ‘later’, ‘git2r’, ‘magrittr’, ‘datasets’, ‘pillar’, ‘rlang’, ‘utils’, ‘fs’, ‘rstudioapi’, ‘graphics’, ‘base’, ‘rsthemes’, ‘tools’, ‘glue’, ‘teamtools’, ‘purrr’, ‘compiler’, ‘pkgconfig’, ‘stats’, ‘methods’, ‘usethis’, ‘tibble’ 0.375s: startup::startup()-specific processing ... done 0.375s: The following will be processed next by R: 0.375s: - R_HISTFILE: ‘’ 0.375s: - ‘./.Rhistory’ (58 lines; 1780 bytes) 0.377s: - .First(): no such function on search() 0.377s: - Remaining packages per R_DEFAULT_PACKAGES to be attached by base::.First.sys() (in order): Warning message: In check_rstudio_option_error_conflict(debug = debug) : startup::check(): CONFLICT: Option ‘error’ was set during the R startup, but this will be overridden by the RStudio settings (menu ‘Debug -> On Error’) when using the RStudio Console. To silence this warning, set option 'error' using ‘if (!startup::sysinfo()$rstudio) options(error = ...)’. For further details on this issue, see https://github.com/rstudio/rstudio/issues/3007 ```
startup::startup(debug = TRUE) without renv ```r > startup::startup(debug = T) 0.000s: System information: 0.001s: - R_HOME: ‘/usr/lib64/R’ (existing folder) 0.002s: - R call: RStudio --interactive 0.002s: - Current directory: ‘/home/pjs/git/mlr-org/mlr3’ 0.003s: - User's home directory: ‘~’ => ‘/home/pjs’ (existing folder) 0.003s: - Search path: ‘.GlobalEnv’, ‘tools:rstudio’, ‘package:stats’, ‘package:graphics’, ‘package:grDevices’, ‘package:utils’, ‘package:datasets’, ‘package:methods’, ‘Autoloads’, ‘package:base’ 0.003s: - Loaded namespaces: ‘compiler’, ‘startup’, ‘graphics’, ‘tools’, ‘utils’, ‘grDevices’, ‘stats’, ‘datasets’, ‘methods’, ‘packrat’, ‘base’ 0.003s: The following has already been processed by R: 0.004s: - R_ENVIRON: ‘’ 0.004s: - R_ENVIRON_USER: ‘’ 0.006s: - ‘/usr/lib64/R/etc/Renviron’ (22 lines; 1697 bytes) setting 22 environment variables (‘R_PLATFORM’, ‘R_PAPERSIZE_USER’, ‘R_PAPERSIZE’, ‘R_PRINTCMD’, ‘R_RD4PDF’, ‘R_TEXI2DVICMD’, ‘R_GZIPCMD’, ‘R_UNZIPCMD’, ‘R_ZIPCMD’, ‘R_BZIPCMD’, ‘R_BROWSER’, ‘EDITOR’, ‘PAGER’, ‘R_PDFVIEWER’, ‘LN_S’, ‘MAKE’, ‘SED’, ‘TAR’, ‘R_SYSTEM_ABI’, ‘R_STRIP_SHARED_LIB’, ‘R_STRIP_STATIC_LIB’, ‘R_LIBS_USER’) 0.007s: - ‘~/.Renviron’ => ‘/home/pjs/.Renviron’ (0 lines; 0 bytes) setting 0 environment variables 0.007s: - R_DEFAULT_PACKAGES: ‘’ (= ‘base,methods,datasets,utils,grDevices,graphics,stats’) 0.007s: - R_LIBS: ‘’ 0.008s: - R_LIBS_SITE: ‘’ 0.008s: - R_LIBS_USER: ‘~/R/x86_64-pc-linux-gnu-library/3.6’ 0.008s: - R_PROFILE: ‘’ 0.008s: - R_PROFILE_USER: ‘’ 0.009s: - ‘.Rprofile’ (0 code lines; 27 bytes) 0.009s: startup::startup()-specific processing ... 0.009s: Found startup directory ‘~/.Renviron.d’. 0.014s: Processing 2 Renviron files ... 0.014s: - ‘/home/pjs/.Renviron.d/Github_PAT.R’ (1 lines; 52 bytes) setting 1 environment variables (‘GITHUB_PAT’) 0.015s: - ‘/home/pjs/.Renviron.d/envs.R’ (2 lines; 159 bytes) setting 2 environment variables (‘_R_CHECK_LENGTH_1_CONDITION_’, ‘R_REMOTES_UPGRADE’) 0.015s: Processing 2 Renviron files ... done 0.018s: Found startup directory ‘~/.Rprofile.d’. 0.021s: Processing 5 Rprofile files ... 0.021s: - ‘/home/pjs/.Rprofile.d/repos.R’ (3 code lines; 223 bytes) 0.021s: - ‘/home/pjs/.Rprofile.d/rstudio-theme.R’ (11 code lines; 477 bytes) 0.093s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/load-at-start.R’ (2 code lines; 47 bytes) 0.227s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/load-at-start.R##hpc’ (1 code lines; 24 bytes) 0.228s: - ‘/home/pjs/.Rprofile.d/sysname=Linux/options.R’ (32 code lines; 2150 bytes) 0.375s: Processing 5 Rprofile files ... done 0.375s: - unloading the ‘startup’ package 0.376s: - Search path: ‘.GlobalEnv’, ‘package:usethis’, ‘package:teamtools’, ‘tools:rstudio’, ‘package:stats’, ‘package:graphics’, ‘package:grDevices’, ‘package:utils’, ‘package:datasets’, ‘package:methods’, ‘Autoloads’, ‘package:base’ 0.376s: - Loaded namespaces: ‘Rcpp’, ‘grDevices’, ‘packrat’, ‘crayon’, ‘later’, ‘git2r’, ‘magrittr’, ‘datasets’, ‘pillar’, ‘rlang’, ‘utils’, ‘fs’, ‘rstudioapi’, ‘graphics’, ‘base’, ‘rsthemes’, ‘tools’, ‘glue’, ‘teamtools’, ‘purrr’, ‘compiler’, ‘pkgconfig’, ‘stats’, ‘methods’, ‘usethis’, ‘tibble’ 0.376s: startup::startup()-specific processing ... done 0.376s: The following will be processed next by R: 0.377s: - R_HISTFILE: ‘’ 0.377s: - ‘./.Rhistory’ (58 lines; 1780 bytes) 0.379s: - .First(): no such function on search() 0.379s: - Remaining packages per R_DEFAULT_PACKAGES to be attached by base::.First.sys() (in order): ```
HenrikBengtsson commented 4 years ago

Thanks for reporting. I can reproduce this in the RStudio Console.

With startup::startup() in ~/.Rprofile, and then setup an renv-initiated folder:

$ mkdir issue_076
$ cd issue_076
$ Rscript -e "renv::init(force=TRUE)" -e "renv::install('startup')"
* Discovering package dependencies ... Done!
* Copying packages into the cache ... Done!
* Lockfile written to '~/tmp/issue_076/renv.lock'.
.Rprofile error: there is no package called 'startup'
Retrieving 'https://cloud.r-project.org/src/contrib/startup_0.13.0.tar.gz' ...
    OK [file is up to date]
Installing startup [0.13.0] ...
OK (linked cache)

Then, when starting the RStudio Console in this folder:

$ cd issue_076
$ rstudio

and selecting 'File' -> 'Existing Directory' -> '~/tmp/issue_076' -> 'Create Project', we'll get:

* Project '~/tmp/issue_076' loaded. [renv 0.8.3]
Warning message:
In check_rstudio_option_error_conflict(debug = debug) :
startup::check(): CONFLICT: Option 'error' was set during the R startup, but
this will be overridden by the RStudio settings (menu 'Debug -> On Error')
when using the RStudio Console. To silence this warning, set option 'error'
using 'if (!startup::sysinfo()$rstudio) options(error = ...)'. For further
details on this issue, see https://github.com/rstudio/rstudio/issues/3007

As expected, it does not happend at the terminal when using plain R or the RStudio Terminal.

Troubleshooting

What's interesting to notice is that the error options is set as it should in the RStudio Console;

> getOption("error")
(function () 
{
    .rs.recordTraceback(TRUE, 5, .rs.enqueueError)
})()

However, if we update ~/.Rprofile to:

print(getOption("error"))
startup::startup()

and ./.Rprofile to:

source("renv/activate.R")
print(getOption("error"))

we'll get that renv sets option error temporarily to:

(function (...) 
{
    calls <- head(sys.calls(), n = -1L)
    frames <- head(sys.frames(), n = -1L)
    formatted <- renv_error_format(calls, frames)
    writeLines(formatted, con = stderr())
})()

which is what startup::startup() complains about. Then, renv unsets the error option to NULL afterward. After the whole R startup process has completed, then the RStudio Console kicks in and will set that final error option;

(function () 
{
    .rs.recordTraceback(TRUE, 5, .rs.enqueueError)
})()

Action

I'll see what I can come up with. Maybe a way to disable this check via an argument, an option, or an environment variable.

pat-s commented 4 years ago

I like the label 😄 Could also be "niche maintenance annoyancy" ;)

HenrikBengtsson commented 4 years ago

This has been fixed in the develop branch (by skipping the check when env var RENV_R_INITIALIZING is TRUE. Thxs again for the report.

pat-s commented 4 years ago

Thanks Henrik!

Works for me.