Installation error when initializing Packrat for a project

I have created a R project in RStudio and now I am trying to initialize Packrat with the following command:

packrat::init(options = list(auto.snapshot = TRUE, vcs.ignore.src = TRUE, use.cache = TRUE))

These are the packages that tries to add to packrat:

Adding these packages to packrat:
              _       
    Rcpp        1.0.2 
    base64enc   0.1-3 
    digest      0.6.20
    evaluate    0.14  
    glue        1.3.1 
    highr       0.8   
    htmltools   0.3.6 
    jsonlite    1.6   
    knitr       1.24  
    magrittr    1.5   
    markdown    1.1   
    mime        0.7   
    packrat     0.5.0 
    rmarkdown   1.14  
    stringi     1.4.3 
    stringr     1.4.0 
    tinytex     0.15  
    xfun        0.8   
    yaml        2.2.0 

But when it tries to install knitr, the following error occurs:

Error: Command failed (1)

Failed to run system command:

	'/usr/lib/R/bin/R' --vanilla CMD INSTALL '/tmp/RtmpequoVT/knitr' --library='/path/to/project/NewProject/packrat/lib/x86_64-pc-linux-gnu/3.6.1' --install-tests --no-docs --no-multiarch --no-demo 

The command failed with output:
* installing *source* package 'knitr' ...
** package 'knitr' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** tests
** byte-compile and prepare package for lazy loading
Error : package 'stringi' was installed by an R version with different internals; it needs to be reinstalled for use with this R version
Error: unable to load R code in package 'knitr'
Execution halted
ERROR: lazy loading failed for package 'knitr'
* removing '/path/to/project/NewProject/packrat/lib/x86_64-pc-linux-gnu/3.6.1/knitr'
Además: Warning messages:
1: In untar(src, exdir = target, compressed = "gzip") :
  argument 'compressed' is ignored for the internal method
2: In untar(src, compressed = "gzip", list = TRUE) :
  argument 'compressed' is ignored for the internal method

I have removed knitr and stringi and installed them again, but the error remains. What can I do? Thank you in advance!

1 Like

Welcome to RStudio Community!

That is strange that re-installing the packages didn't fix the issue. What version of R and packrat are you using? Could you run sessionInfo() after you receive the error?

I created a project on RStudio Cloud to reproduce the example (hopefully you'll be able to access it via that link). I was able to run the exact same command without error using R 3.6.0 and packrat 0.5.0.

> packrat::init(options = list(auto.snapshot = TRUE, vcs.ignore.src = TRUE, use.cache = TRUE))
Initializing packrat project in directory:
- "/cloud/project"

Adding these packages to packrat:
             _      
    evaluate   0.14 
    glue       1.3.1
    highr      0.8  
    knitr      1.24 
    magrittr   1.5  
    markdown   1.1  
    mime       0.7  
    packrat    0.5.0
    stringi    1.4.3
    stringr    1.4.0
    xfun       0.8  
    yaml       2.2.0

Fetching sources for evaluate (0.14) ... OK (RSPM current)
Fetching sources for glue (1.3.1) ... OK (RSPM current)
Fetching sources for highr (0.8) ... OK (RSPM current)
Fetching sources for knitr (1.24) ... OK (CRAN current)
Fetching sources for magrittr (1.5) ... OK (RSPM current)
Fetching sources for markdown (1.1) ... OK (CRAN current)
Fetching sources for mime (0.7) ... OK (RSPM current)
Fetching sources for packrat (0.5.0) ... OK (RSPM current)
Fetching sources for stringi (1.4.3) ... OK (RSPM current)
Fetching sources for stringr (1.4.0) ... OK (RSPM current)
Fetching sources for xfun (0.8) ... OK (RSPM current)
Fetching sources for yaml (2.2.0) ... OK (RSPM current)
Snapshot written to '/cloud/project/packrat/packrat.lock'
Installing evaluate (0.14) ... 
	OK (built source)
Installing glue (1.3.1) ... 
	OK (built source)
Installing highr (0.8) ... 
	OK (built source)
Installing magrittr (1.5) ... 
	OK (built source)
Installing mime (0.7) ... 
	OK (built source)
Installing packrat (0.5.0) ... 
	OK (built source)
Installing stringi (1.4.3) ... 
	OK (built source)
Installing xfun (0.8) ... 
	OK (built source)
Installing yaml (2.2.0) ... 
	OK (built source)
Installing stringr (1.4.0) ... 
	OK (built source)
Installing markdown (1.1) ... 
	OK (built source)
Installing knitr (1.24) ... 
	OK (built source)
Initialization complete!
There were 24 warnings (use warnings() to see them)

Restarting R session...

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
 [5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C             
 [9] LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.24    stringi_1.4.3

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0    xfun_0.8       packrat_0.5.0 

I'm running R 3.6.1 and Packrat 0.5.0. This is what sessionInfo() returns:

R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS:   /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=es_ES.UTF-8     LC_MONETARY=es_ES.UTF-8   
 [6] LC_MESSAGES=es_ES.UTF-8    LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.6.1  magrittr_1.5    htmltools_0.3.6 tools_3.6.1     yaml_2.2.0      Rcpp_1.0.2      stringi_1.4.3   rmarkdown_1.14 
 [9] knitr_1.24      stringr_1.4.0   digest_0.6.20   xfun_0.8        packrat_0.5.0   evaluate_0.14  

And, by the way, I have also tried reinstalling all the packages that knitr directly/indirectly depends on: (mime, glue, magrittr, stringi, evaluate, highr, markdown, stringr, yaml, xfun and, of course, knitr). The error is still the same.

1 Like

Finally! I have managed to initialize it correctly. I removed all the packages related to knitr (mime, glue, magrittr, stringi, evaluate, highr, markdown, stringr, yaml, xfun and, of course, knitr). But, before reinstalling them, I also deleted manually the folders I found in /home/username/.config/packrat/v2/library. It seems that Packrat was taking that directory as the source for some of the packages (which ones? I have no idea :man_shrugging:t2:) and, hence, the error. After that, I reinstalled all the packages again, initialized Packrat and... :tada::tada:

Anyhow, thanks for the help @jdblischak

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.