.Rprofile's search path is not the same as the default one

42 Views Asked by At

Consider the two lines below:

Sys.setenv(R_IMPORT_PATH = "/path/to/my/r_import")
foo <- modules::import("foo")

If I execute this code from within an already-established interactive R session, it works fine.

But if I put the same two lines in my .Rprofile and start a new interactive R session, the modules::import line fails with

Error in module_init_files(module, module_path) : 
  could not find function "setNames"

If I then attempt the following fix/hack

Sys.setenv(R_IMPORT_PATH = "/path/to/my/r_import")
library(stats)
foo <- modules::import("foo")

...then the modules::import line still fails, but with the following

Error in lapply(x, f) : could not find function "lsf.str"

So the idea of patching the missing names seems like it will be an unmaintainable nightmare...


The crucial issue is this: It appears that the search path right after an interactive search session starts is different from the one that an .Rprofile script sees.

Q1: Is there a way that I can tell R to make the search path exactly as it will be when the first > prompt appears in the interactive session?

Q2: Alternatively, is there a way for the .Rprofile to schedule some code to run after the session's default search path is in place?


NB: Solutions like the following:

Sys.setenv(R_IMPORT_PATH = "/path/to/my/r_import")
library(stats)
library(utils)
foo <- modules::import("foo")

...are liable to break every time that the (third-party) modules package is modified.

0

There are 0 best solutions below