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 ?