Hi all ---
I want to be able to launch a packrat project (non-interactively, via Rscript), but from any arbitrary directory on my system.
For example, imagine this scenario:
/home/me/A/B/my_packrat_project
, and there exists this file:
/home/me/A/B/my_packrat_project/main.R
I'd like to be able to run main.R (via Rscript) from any current PWD, e.g. if my PWD is /home/me, then:
Rscript A/B/my_packrat_project/main.R
To force reading of the packrat project's .Rprofile, I can do this:
R_PROFILE_USER=A/B/my_packrat_project/.Rprofile && Rscript A/B/my_packrat_project/main.R
But(!), packrat's source() command in the .Rprofile is only locally-aware... it expects one to source that file from within the packrat package:
source("packrat/init.R")
I don't want to switch working directories during the script's execution, so I thought about:
(1) copying the PWD to be passed as a command-line argument to main.R,
(2) switch to the project directory, start R,
(3) then at the start of main.R, use setwd() to jump back to PWD for execution.
It's a super-kludgey workaround, though, so I thought I'd ask to see if/how others have dealt with this previously.
Thoughts?
Cheers,
-Murat