1

I am using the packrat package for my project the first time, and I want to use a Makefile to run specific scripts in a specific order for different targets. However. I organized my file like this:

  • main_dir/packrat/
  • main_dir/subproject1/R_scripts_1/Makefile

When I run R CMD BATCH someRfile.R from within the Makefile, R is not using the packrat libs, but the default user libs, which is not what I want. Is there any way to force all R processes startet in any subdir of the packrat dir, to use only the packrat libs?!

Thank you!

Manuel
  • 265
  • 3
  • 11

2 Answers2

1

I guess you have to include source("packrat/init.R") at the very start of someRfile.R as in your .Rprofile file in your project folder.

I assume that you use R studio in the above comment.

  • Thank you for your reply, but this does not work for me. I tried to figure out how packrat change the default libs ... it seems not to happen in `init.R`. – Manuel Nov 25 '17 at 09:14
  • I see your point. Then I guess the best option is to use the `.libPaths` function at the start of `someRfile.R` to set the library paths to the sub directories of the `packrat` directory. – Benjamin Christoffersen Nov 25 '17 at 13:41
  • Hi. I know I can do this with `.libPaths()` but I thought there would be a smoother way to do that, because I have a lot of files (ok I could make a separate `.Renviron`for each folder.) and a lot of subproject folders. :-( – Manuel Nov 25 '17 at 18:27
1

Just had this issue - the following fixed it.

Add an .Rprofile to each subdirectory (and sub-subdirectory etc.) containing the following,

source("../.Rprofile", chdir = TRUE)

From the packrat docs

Sam Abbott
  • 466
  • 2
  • 9