2

I have a RMD file. I can knit it with knitr from RStudio interface. But when I try to run a separate chunk in console I got errors:

Error in library(bla) : there is no package called bla

where bla is my homemade package. I haven't installed bla to my current project. I have packrat initialised and bla absent from packrat directories. So both ways should not work.

Call .libPaths() shows me

> .libPaths()
[1] "/home/user/projdir/packrat/lib/x86_64-pc-linux-gnu/3.4.0" 
[2] "/home/user/projdir/packrat/lib-ext/x86_64-pc-linux-gnu/3.4.0" 
[3] "/home/user/projdir/packrat/lib-R/x86_64-pc-linux-gnu/3.4.0" 

I've added .libPaths() call to my document and got:

[1] "/home/user/Documents/projdir/packrat/lib/x86_64-pc-linux-gnu/3.4.0"
[2] "/home/user/Documents/projdir/packrat/lib-ext/x86_64-pc-linux-gnu/3.4.0"   
[3] "/home/user/Documents/projdir/packrat/lib-R/x86_64-pc-linux-gnu/3.4.0"   
[4] "/home/user/R/x86_64-pc-linux-gnu-library/3.4"
[5] "/usr/local/lib/R/site-library"
[6] "/usr/lib/R/site-library"
[7] "/usr/lib/R/library" 

Why the paths differ? And how can I force knitr to use packages only from packrat?

testlnord
  • 438
  • 1
  • 5
  • 14
  • Something is weird. 5, 6, and 7 of the second answer are the standard Debian (and Ubuntu and other derivatives) setting you should also have in the first answer. Now, I don't use `packrat` myself so I don't know what it does -- but all the default R behaviour (and then some) is explained in `help(Startup)`. There are some env. vars. you can check. – Dirk Eddelbuettel Jun 13 '19 at 04:29

0 Answers0