Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib path is not set correctly if it is also set in .Renviron #83

Closed
gaborcsardi opened this issue Oct 23, 2018 · 3 comments
Closed

lib path is not set correctly if it is also set in .Renviron #83

gaborcsardi opened this issue Oct 23, 2018 · 3 comments

Comments

@gaborcsardi
Copy link
Member

See r-lib/revdepcheck#160

@gaborcsardi
Copy link
Member Author

This is because we use profiles to override the .Renviron R lib setup, but R CMD check runs the examples and tests with --vanilla, so the profiles are not used, but .Renviron still is. Reprex:

readLines("~/.Renviron")
#> [1] "R_LIBS=~/R:/tmp/empty"

.libPaths()
#> [1] "/Users/gaborcsardi/R"                                          
#> [2] "/private/tmp/empty"                                            
#> [3] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library"
.libPaths(.libPaths()[1])
.libPaths()
#> [1] "/Users/gaborcsardi/R"                                          
#> [2] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library"

f <- function() {
  system("R -q -e '.libPaths()'", intern = TRUE)
}

f2 <- function() {
  system("R --vanilla -q -e '.libPaths()'", intern = TRUE)
}

callr::r(f)
#> [1] "> .libPaths()"                                                         
#> [2] "[1] \"/Users/gaborcsardi/R\"                                          "
#> [3] "[2] \"/Library/Frameworks/R.framework/Versions/3.5/Resources/library\""
#> [4] "> "                                                                    
#> [5] "> "

callr::r(f2)
#> [1] "> .libPaths()"                                                         
#> [2] "[1] \"/Users/gaborcsardi/R\"                                          "
#> [3] "[2] \"/private/tmp/empty\"                                            "
#> [4] "[3] \"/Library/Frameworks/R.framework/Versions/3.5/Resources/library\""
#> [5] "> "                                                                    
#> [6] "> "

Created on 2018-10-24 by the reprex package (v0.2.1)

@gaborcsardi
Copy link
Member Author

Ideally, a callr call should re-create the exact same context in the subprocess, w.r.t. the library path settings. This means that callr should clean up after itself, by removing the fake profiles, as soon as it has loaded. This is possible in callr::r and friends, but not easily in callr::rcmd and friends, unless we use the R_TESTS trick.

OTOH, this conservative behavior would make it really hard to work with private libraries if one have an R_LIBS= setting in ~/.Renviron. Since R will read this for R CMD check examples and tests, they would escape from the private lib.

@gaborcsardi
Copy link
Member Author

See also #73.

So, for practical reasons, we try to make sure that non-callr child processes of the child process inherit the same settings. This means that we have to be more aggressive setting R_LIBS, etc. env. vars, and/or more aggressive shadowing .Renviron.

Since .Renviron is applied after the R_LIBS etc. vars are set (in the parent), we definitely need to do that. So we append the setting of R_LIBS_SITE and R_LIBS to the fake .Renviron file(s). If R_LIBS_USER was not used, then we set that as well, to empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant