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

Use library path of a fresh R session #255

Open
renkun-ken opened this issue Jun 10, 2023 · 2 comments
Open

Use library path of a fresh R session #255

renkun-ken opened this issue Jun 10, 2023 · 2 comments
Labels
feature a feature request or enhancement

Comments

@renkun-ken
Copy link

renkun-ken commented Jun 10, 2023

In the documentation of r_session, the description libpath argument says

libpath: Library path for the subprocess. By default the same as the current library path. I.e. not necessarily the library path of a fresh R session.)

I wonder if it is possible to keep the library path of a fresh R session instead of propagating from the main session?

My motivation is that I need to start an R session from a specific working directory so that the folder .Rprofile is respected (e.g. renv projects or any other startup customization) so that I can call session$run() with the proper R libpath setup specific to that directory. In this use case, it is best that the spawned R session should behave exactly the same as if the session is a fresh session started from the specific working directory.

@renkun-ken
Copy link
Author

renkun-ken commented Jun 10, 2023

In a working directory without user .Rprofile

callr::r(function() .libPaths(), libpath = character(), system_profile = TRUE, user_profile = TRUE)

works properly.

But if I create a folder where a user .Rprofile with the following

library(data.table)
.libPaths(
  c(normalizePath("~/test/test1/R"), .libPaths())
)

and run the following in the master session:

setwd(normalizePath("~/test/test1"))
callr::r(function() .libPaths(), libpath = character(), system_profile = TRUE, user_profile = TRUE)

the following error occurs:

Error in `get_result(output = out, options)`:
! callr subprocess failed: could not start R, exited with non-zero status, has crashed or was killed
ℹ See `$stderr` for standard error.
Type .Last.error to see the more details.
Backtrace:
1: stop(cond)
2: throw(new_callr_crash_error(output, killmsg))
3: get_result(output = out, options)
4: r(func, args = args, libpath = libpath, repos = repos, cmdargs = cmdargs, 
5: callr::r_vanilla(function() .libPaths(), libpath = character(),

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Jun 14, 2023
@gaborcsardi
Copy link
Member

Yeah, it would make sense to have an option for this.

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

No branches or pull requests

2 participants