starting a packrat project from outside the project directory

155 views
Skip to first unread message

Murat Tasan

unread,
Mar 3, 2015, 7:18:24 PM3/3/15
to packrat...@googlegroups.com
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

Kevin Ushey

unread,
Mar 13, 2015, 3:01:52 PM3/13/15
to packrat...@googlegroups.com
Hi Murat,

We intentionally wanted to keep the .Rprofile as clean as possible, to avoid clutter / 'scaring' users -- we hide as much logic as possible within `packrat/init.R` -- and ensuring a sub-process is called within the project directory seems like not that 'bad' of a workaround.

That said, we are open to proposals to make the startup more flexible -- perhaps, the `init.R` script could respect some command line arguments.

Thoughts?
Kevin

Holger Hoefling

unread,
Aug 7, 2015, 7:48:17 AM8/7/15
to packrat-discuss
For what is the init exactly all needed. For the analysis work - simply pointing to the right library directory using .libPaths() should be sufficient, right? And when people actually want to install from github or snapshot - one can just load packrat specifically for that. Or would I be breaking something with this approach?

Best

Holger
Reply all
Reply to author
Forward
0 new messages