5
votes

I am pretty desperate to install.packages("devtools"). However it allways fails with this error

Error: .onLoad failed in loadNamespace() for 'pkgload', details:
  call: readRDS(nsInfoFilePath)
  error: error reading from connection
Execution halted
ERROR: lazy loading failed for package ‘devtools’
* removing ‘/home/bjoern/R/x86_64-pc-linux-gnu-library/3.6/devtools’

Things I tried to fix this:

  1. Add the dependencies = T argument
  2. Following a suggestion by hadley wickham on github -> update rlang package
  3. Try to run install.packages("pkgload") resulting in nearly exactly the same error (see below)
  4. Completely removing R and reinstalling it
  5. Additionally installing package following packages:
    • r-base-dev
    • r-cran-devtools
    • r-recommended
  6. Updated all packages update.packages(ask = FALSE, checkBuilt = TRUE)

Error of install.packages("pkgload")

Error: package or namespace load failed for ‘pkgload’:
 .onLoad failed in loadNamespace() for 'pkgload', details:
  call: readRDS(nsInfoFilePath)
  error: error reading from connection
Error: loading failed
Execution halted
ERROR: loading failed

I digged even deeper to the pkgload (which at least I hope is the only reason for the problem). I will check if manually (re)installing all imports and suggests from the CRAN page of pkgload does solve it.

Imports: desc, methods, pkgbuild, rlang, rprojroot, rstudioapi, utils, withr
Suggests: bitops, covr, Rcpp, testthat


My sessionInfo() output:
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_DE.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.3 tools_3.6.3

I still refuse to belief that it is impossibe to install devtools on ubuntu20
However at this point I take any straw

Solution Edit:

In short what fixed the issue for me was installing testthat package before. Thanks to comment by rui-barradas

install.packages("testthat") 
install.packages("pkgload") 
install.packages("devtools") 
2
"I still refuse to belief that it is impossibe to install devtools on ubuntu20" Good! I know for certain it's possible to install devtools on Ubuntu 20.04 as I have it installed on 20.04! However, my R version is 4.0.0, so there might be some difference there. This seems like a potentially tough problem to debug. You may want to make sure there are no R packages installed (i.e., removing r-cran-devtools and any packages in your /home/user/R/ folder), then start from just install.packages("pkgload") - duckmayr
@duckmayr Same here, Ubuntu 20.04/R4.0.0 all went so-so well. The problem is that I have to manually install each and every dependency that was already installed prior to 4.0.0. Meaning, before pkgload was installed I had to run install.packages('testthat'). - Rui Barradas
if/when you apt-get install r-cran-devtools (after adding Michael Rutter's PPA to your repository list as per the Ubuntu-specific instructions on the CRAN site), does it work? That should be sufficient to install a binary version of the package (although I'd love to know why you're having trouble installing from source) - Ben Bolker
@RuiBarradas wow that fixed it. Just had to manually install install.packages('testthat') before. Now pkgload works as a charm and devtools was successfully installed as well. Looks like there is already an issue on github for this - Björn
You want to wrap this up as an answer? As others might run into the same scenario? @RuiBarradas - Björn

2 Answers

4
votes

I am also on Ubuntu 20.04 but running R 4.0.0.

When trying to install a package, if it depends on another that was installed prior to R 4.0.0 I get an error message and the installation fails. This happens even if I set dependencies = TRUE in the call to install.packages.

Example: The command was

install.packages('pkgload')

I omit the first output lines, saying that the file was downloaded. Then, the relevant part.

  • installing source package ‘pkgload’ ...
    ** package ‘rcmdcheck’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading Error: package ‘testthat’ was installed before R 4.0.0: please re-install it
    Execution halted ERROR: lazy loading failed for package ‘pkgload’
  • removing ‘/usr/local/lib/R/site-library/pkgload’
  • restoring previous ‘/usr/local/lib/R/site-library/pkgload’ Warning in install.packages : installation of package ‘pkgload’ had non-zero exit status The downloaded source packages are in
    ‘/tmp/RtmpVxpbs0/downloaded_packages’

Correct way.
The right way of installing package pkgload was to run the sequence

install.packages('testthat')
install.packages('pkgload')

and the problem was solved.

Note that with other packages, it already happened to see this be a recursive issue. Imagine that package testthat depended (which it does not) on another package installed prior to R 4.0.0.

Annoying but solvable.

sessionInfo()  
#R version 4.0.0 (2020-04-24)  
#Platform: x86_64-pc-linux-gnu (64-bit)  
#Running under: Ubuntu 20.04 LTS  
#  
#Matrix products: default  
#BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0  
#LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0  
#  
#locale:  
# [1] LC_CTYPE=pt_PT.UTF-8       LC_NUMERIC=C                
#[3] LC_TIME=pt_PT.UTF-8        LC_COLLATE=pt_PT.UTF-8      
# [5] LC_MONETARY=pt_PT.UTF-8    LC_MESSAGES=pt_PT.UTF-8     
# [7] LC_PAPER=pt_PT.UTF-8       LC_NAME=C                   
# [9] LC_ADDRESS=C               LC_TELEPHONE=C                
#[11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C           
#  
#attached base packages:  
#[1] stats     graphics  grDevices utils     datasets   
#[6] methods   base       
#  
#other attached packages:  
#[1] rvest_0.3.5       xml2_1.3.2        data.table_1.12.8  
#
#loaded via a namespace (and not attached):  
2
votes

I had the same problems, and the solution was, at least in my case, Ubuntu 20.04.1 LTS (Focal Fossa) + R 4.0.2:

First (from terminal), install:

Step 1: sudo apt-get update -y
Step 2: sudo apt-get install -y libxml2-dev

Then from RStudio (setRepositories first, and choose 8 repositories) and install both packages:

  1. Install xml2 package

  2. install devtools

And works for me.