Failling install Devtools: Error: .onLoad failed in loadNamespace() for 'pkgload'

Hi guys,

my google research didn't bring up any usefull results and at this point I don't know what I could try anymore. I am trying to install devtools, in the following setup:

  • Ubuntu 20.04 (Virtualboax)
  • R.version.string = "R version 3.6.3 (2020-02-29)"
  • New installation of RStudio (Version 1.2.5042)

I tried to google the specific error ("Error: .onLoad failed in loadNamespace() for 'pkgload', details:"). I found this one link on which the legendary hadley wickham suggested updating the rlang package. Which I did. However it didn't fix the issue.
Has anybody any idea?
I also installed the necessary system dependenvies. However I just got those after I already started the install.packages("devtools")

sudo apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
> install.packages("devtools")
Installing package into ‘/home/bjoern/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/devtools_2.3.0.tar.gz'
Content type 'application/x-gzip' length 375227 bytes (366 KB)
==================================================
downloaded 366 KB

* installing *source* package ‘devtools’ ...
** package ‘devtools’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
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’
Warning in install.packages :
  installation of package ‘devtools’ had non-zero exit status

Restart your R session and try to reinstall pkgload package, then try to install devtools again.

install.packages("pkgload")
1 Like

Hi andresrcs, thank you very much for answer/ help.
I restarted the system / RStudio as well as the R session.
Installing in "pkgload", which results sadly in a similar looking error:

> install.packages("pkgload")
Installing package into ‘/home/bjoern/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/pkgload_1.0.2.tar.gz'
Content type 'application/x-gzip' length 55605 bytes (54 KB)
==================================================
downloaded 54 KB

* installing *source* package ‘pkgload’ ...
** package ‘pkgload’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-jbaK_j/r-base-3.6.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c unlock.c -o unlock.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o pkgload.so unlock.o -L/usr/lib/R/lib -lR
installing to /home/bjoern/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-pkgload/00new/pkgload/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
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
* removing ‘/home/bjoern/R/x86_64-pc-linux-gnu-library/3.6/pkgload’
* restoring previous ‘/home/bjoern/R/x86_64-pc-linux-gnu-library/3.6/pkgload’
Warning in install.packages :
  installation of package ‘pkgload’ had non-zero exit status

This is weird, just to rule out a permissions issue, can you try installing from the terminal (not the R console) with this command

sudo su - -c "R -e \"install.packages('pkgload', repos='http://cran.rstudio.com/')\""

Thank you again. I solved it in the meantime (with help from SO, tbh).
I had to install testthat before trying to install pkgload.
So the final solution (in R code) looked like this:

install.packages("testthat") 
install.packages("pkgload") 
install.packages("devtools") 

This seems to be a known problem (at least I found a similar report on pkgload's github). Despite in my case, the error was not as clear as on the github page. However installing testthat beforehand solved the issue for me.

1 Like

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