I'm building an RStudio project (Project 2) where I would like to access certain scripts that are contained within another already-built RStudio project (Project 1). Project 1 contains various scripts, some of which reference one another through source()
calls. Is there any way to achieve this? I originally thought that by using here::here() or box::file() in Project 1 could facilitate this, however I realized that both of those functions will reference the working directory of Project 2 as opposed to that of Project 1.
For example, let's say Project 1 contains the following file structure:
> list.files(withr::with_dir("./Project_1", getwd()))
[1] "assumptions.R" "launch.R" "output.R"
[4] "project_env.R" "renv" "renv.lock"
[7] "run_scenarios.R" "Project_1.Rproj" "sample_script_1.R"
[10] "sample_script_2.R" "selected_assumptions.R"
And Launch.R is the script that launches code for all of the remaining scripts (code below).
Launch.R
source("assumptions.R")
source("project_env.R")
project_env$launch_mode = project_env$scenario_toggle$DEFAULT
source("assumptions.R")
source("selected_assumptions.R")
source("output.R")
source("run_scenarios.R")
Is there any way to execute the Launch.R script from outside of Project 1? Because of the way Project 1's scripts are tied together, if I try to execute Launch.R from anywhere outside of the project, I get errors as soon as it tries to execute the source("assumptions.R")
command.
Any help would be much appreciated.
I had the same issue, and I could resolve it with
See
here
package website for details. https://cran.r-project.org/web/packages/here/vignettes/here.html