3

I built a package using packrat to deal with dependencies versions.

@nyzls65c:~/private/research$ tree -L 1 -a sp.util  
sp.util                                                     
|-- .Rbuildignore                                           
|-- .Rhistory                                               
|-- .Rprofile                                               
|-- .Rproj.user                                             
|-- DESCRIPTION                                             
|-- NAMESPACE                                               
|-- R                                                       
|-- Read-and-delete-me                                      
|-- man                                                     
|-- packrat                                                 
|-- sp.util.Rproj 

When I start R from the package path ~/private/research/sp.util I can see that packrat deals with my libraries:

@nyzls65c:~/private/research/sp.util$ Rscript -e ".libPaths()"                       
WARNING: ignoring environment value of R_HOME                                                
[1] "~/private/research/sp.util/packrat/lib/x86_64-redhat-linux-gnu/3.3.0"
[2] "~/private/research/sp.util/packrat/lib-ext"                          
[3] "~/private/research/sp.util/packrat/lib-R"

When I start from anywhere else

@nyzls65c:~/private/research$ Rscript -e ".libPaths()"        
WARNING: ignoring environment value of R_HOME                         
NULL                                                                  
[1] "~/R/x86_64-redhat-linux-gnu-library/3.3"      
[2] "/usr/lib64/R/library"                                            
[3] "/usr/share/R/library"                                            

I guess what packrat does is loading the .Rprofile file it generates in the package directory and setup the .libPaths().

The problem is that then when I do library(sp.util), unless I am in the right directory the wrong packages will be loaded. (I tested by doing sessionInfo() while starting from within /sp.util and without and quite logically the packages in Depends are not the same)

What I want to do is use Rscript /path/script.r, load sp.util within script.r and have the correct (ie packrat-local ones) dependencies loaded. I do not want to have to start Rscript from a given path.

Do I need to set the libPaths() myself with R_LIB_USER to do it ?

And say I need multiple packages using packrat is it even a viable option to do the above ?

statquant
  • 13,672
  • 21
  • 91
  • 162
  • I'm having the same issues at the moment, any luck? – DaveRGP Jan 18 '17 at 14:36
  • nope, this question is left hanging – statquant Jan 18 '17 at 16:44
  • Depending on your use case my current plan is to use `miniCRAN` package to build a locally managed repo on the network I am deploying over. This may be suitable for you depending on your use case. – DaveRGP Jan 18 '17 at 19:10
  • well mini cran does not handle several package versions which appears like a must have for me... – statquant Jan 18 '17 at 22:20
  • It will handle a range of different packages, I think, I'll update this if I find out otherwise if you mean I need a copy of data.table 1.9.4 AND 1.9.6 on access depending on R version on the local machine then perhaps theres a clue in this slide 8? http://www.slideshare.net/RevolutionAnalytics/through-the-firewall-with-minicran Suggests using a folder per R version. – DaveRGP Jan 19 '17 at 09:27
  • r version is not the issue, package version is, you cannot have 1.9,2.0,2.1 for the same R – statquant Jan 19 '17 at 10:20
  • From your description, it sounds like this may be blurring the lines between the `packrat` environment (i.e., when you start R in the `sp.util` directory), and the advertised dependencies of the package, as defined by `Depends:` or `Imports:` in the `DESCRIPTION` file. If you need to "hold-back" dependent packages to a specific non-current version, perhaps you should use an equality, such as `Depends: pkgname (== 0.1)` (whereas most of the time, it is an inequality, `pkgname (>= 0.1)`). – r2evans Jun 08 '17 at 16:41

0 Answers0