If I'm using RStudio it is very easy to know if I'm in packrat mode: I just open the packages tab and click the Packrat icon. However, I don't know any commands to do it programatically or outside RStudio. Also, packrat commands such as packrat::status()
work even if I'm not in Packrat mode.
Asked
Active
Viewed 858 times
0

gsmafra
- 2,434
- 18
- 26
-
Why isn't `packrat::status` helpful? If `packrat` has not been initiated you get the corresponding error: `Error: This project has not yet been packified. Run 'packrat::init()' to init packrat.` – LyzandeR Mar 19 '18 at 17:20
-
I get this message only when I'm in a working directory that does not coincide with an RStudio project. When they coincide I get this message: `The following packages are referenced in your code, but are not present in your library nor in packrat: Matrix nlme You will need to install these packages manually, then use packrat::snapshot() to record these packages in packrat.` `nlme` isn't referenced nowhere in my code. – gsmafra Mar 19 '18 at 21:00
-
This message means that packrat is active. One of the functions you use, uses `nlme` internally. Do as the error says and you will be fine – LyzandeR Mar 19 '18 at 23:50
-
Once I open the project in RStudio I'm able to run the code (without `nlme`) and `packrat::status()` says that everything is up to date. – gsmafra Mar 20 '18 at 01:55
1 Answers
1
You use packrat::search_path()
to infer. See how could be done around it:
With packrat disabled.
> packrat::off()
Packrat mode off. Resetting library paths to:
- "/home/ajoe/R/x86_64-pc-linux-gnu-library/3.4"
- "/usr/local/lib/R/site-library"
- "/usr/lib/R/site-library"
- "/usr/lib/R/library"
>
> any(grepl("packrat", packrat::search_path()$lib.dir))
[1] FALSE
With packrat enabled.
> packrat::on()
Packrat mode on. Using library in directory:
- "~/wx/your_project_dir/packrat/lib"
>
> any(grepl("packrat", packrat::search_path()$lib.dir))
[1] TRUE
The same can be achieved with .libPaths()
instead of packrat::search_path()
.

Leo
- 1,102
- 2
- 11
- 18