I am trying to use renv with my project pipeline in R.
My folder structure is
.
|-- data
| |-- file1.rda
| |-- file2.rda
| |-- folder1
| |-- folder2
`-- repository
|-- rep1
| |-- script1.R
| |-- script2.R
| |-- config.json
`-- rep2
/rep1 is the folder of my analysis pipeline and the folder I am running my scripts from. I am keeping track of the packages I am using with renv, which I initialised in /rep1, but I have not created a snapshot yet.
/data contains file*.rda, which are produced by script1.R and have a considerable size. I cannot move any of them in my /rep1 folder. In order to use them with script2.R, I am calling them with
library(renv)
library(jsonlite)
config <- read_json("config.json")
load(file.path(config$data_folder, "file1.rda"))
and they should load the object stored in them.
Whenever I run that, though, I get the following error:
Error: project "~/data/file1.rda" has no activate script and so cannot be activated
Traceback (most recent calls last):
4: load(file.path(config$data_folder, "file1.rda"))
3: renv_load_switch(project)
2: stopf(fmt, renv_path_pretty(project))
1: stop(sprintf(fmt, ...), call. = call.)
Am I missing something? I have the impression something is going wrong when I switch the folder, but I am not really sure how to fix this.
Thank you in advance for your help
The problem here is that renv::load() is masking base::load(). In general, you should not call library(renv) in your scripts -- instead, you should prefix any renv APIs you want to use with renv::.
Alternatively, explicitly call base::load() to ensure the right version of load() is resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With