R: cannot install packages after downgrading from 3.5 to 3.4. Error in dyn.load(file, DLLpath = DLLpath, ...) - r

I had installed R 3.5.1 as detailed in here, but I had some problem with some packages (namely rJava and XML), so I have decided to uninstall R 3.5.1 and downgrade to R 3.4.4 from the Ubuntu 18.04 repositories.
I did that successfully, but now, when I try to reinstall any CRAN package inside R with, for example:
install.packages("ggplot2")
library(ggplot2)
I get the following errors:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so':
/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so: undefined symbol: DATAPTR
ERROR: lazy loading failed for package ‘ggplot2’
* removing ‘/usr/local/lib/R/site-library/ggplot2’
* restoring previous ‘/usr/local/lib/R/site-library/ggplot2’
The downloaded source packages are in
‘/tmp/RtmpFKBMdd/downloaded_packages’
Warning message:
In install.packages("ggplot2") :
installation of package ‘ggplot2’ had non-zero exit status
>
>
>
>
> library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so':
/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so: undefined symbol: DATAPTR
In addition: Warning message:
package ‘ggplot2’ was built under R version 3.5.1
Any clue how to solve this? Thanks

OK this script to remove all user installed packages works like a charm if anyone is interested. It was taken from here.
# Shamlessly stolen from:
# https://www.r-bloggers.com/how-to-remove-all-user-installed-packages-in-r/
# create a list of all installed packages
ip <- as.data.frame(installed.packages())
head(ip)
# if you use MRO, make sure that no packages in this library will be removed
ip <- subset(ip, !grepl("MRO", ip$LibPath))
# we don't want to remove base or recommended packages either\
ip <- ip[!(ip[,"Priority"] %in% c("base", "recommended")),]
# determine the library where the packages are installed
path.lib <- unique(ip$LibPath)
# create a vector with all the names of the packages you want to remove
pkgs.to.remove <- ip[,1]
head(pkgs.to.remove)
# remove the packages
sapply(pkgs.to.remove, remove.packages, lib = path.lib)

Related

Cannot reinstall or run Stringr package

I recently upgrade ubuntu from 18.04 to 20.04, so this is probably related...
My code requires me to have the stringr package and to use tidyverse. When I try to run require(stringr) and library(tidyverse) I receive these errors,
> require(stringr) # String manipulation
Loading required package: stringr
Error: package or namespace load failed for ‘stringr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/stringi/libs/stringi.so':
libicui18n.so.60: cannot open shared object file: No such file or directory
> library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/stringi/libs/stringi.so':
libicui18n.so.60: cannot open shared object file: No such file or directory
I've tried reinstalling stringr using install.packages("stringr") but then get
Installing package into ‘/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/stringr_1.4.0.tar.gz'
Content type 'application/x-gzip' length 135777 bytes (132 KB)
==================================================
downloaded 132 KB
* installing *source* package ‘stringr’ ...
** package ‘stringr’ successfully unpacked and MD5 sums checked
mv: cannot move '/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/stringr' to '/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-stringr/stringr': Permission denied
ERROR: cannot remove earlier installation, is it in use?
* removing ‘/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/stringr’
Warning in install.packages :
installation of package ‘stringr’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmptRvgMm/downloaded_packages’
Although it seems as if Stringr is good to go and all there, when I attempt to use require(stringr) I end up getting this error
Loading required package: stringr Error: package or namespace load failed for ‘stringr’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/home/elrodlab/R/x86_64-pc-linux-gnu-library/3.6/stringi/libs/stringi.so': libicui18n.so.60: cannot open shared object file: No such file or directory
Any idea on how to handle this?
The second message seems to indicate that stringr was actually successfully installed. Try running again
require(stringr)

Error loading R package - libicui18n.so.68: cannot open shared object file

Until yesterday, I could run library(car) just fine. But after running yay -Syyu and upgrading as many packages as I can, this no longer works.
> library(car)
Loading required package: carData
Error: package or namespace load failed for ‘car’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/my-name/R/x86_64-pc-linux-gnu-library/4.0/stringi/libs/stringi.so':
libicui18n.so.68: cannot open shared object file: No such file or directory
I am running this on Arch Linux.
We can install the 'stringi' package
install.packages('stringi')

Loading packages in R and RStudio gives image not found error

When trying to load packages in RStudio or R, I get "image not found" errors, e.g.:
> install.packages("Rcpp")
Installing package into ‘/Users/blah/Library/R/4.0/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.0/Rcpp_1.0.6.tgz'
Content type 'application/x-gzip' length 3203922 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
The downloaded binary packages are in
/var/folders/q5/9z9mngy52lx6gbjtc_tg5w2wwn7x6k/T//RtmpZwoJ1y/downloaded_packages
> library(Rcpp)
Error: package or namespace load failed for ‘Rcpp’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/blah/Library/R/4.0/library/Rcpp/libs/Rcpp.so':
dlopen(/Users/blah/Library/R/4.0/library/Rcpp/libs/Rcpp.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib
Referenced from: /Users/blah/Library/R/4.0/library/Rcpp/libs/Rcpp.so
Reason: image not found
> detach("package:Rcpp", unload = TRUE)
Error in detach("package:Rcpp", unload = TRUE) : invalid 'name' argument
The same thing happens for many other packages in the User Library e.g. sp, kernlab, gplots, gtools (but not all of them e.g. crayon loads ok). Packages in the System library load fine.
Similar things happen in R, but not with the same set of packages e.g. Rcpp works here but kernlab still does not:
> library(Rcpp)
> detach("package:Rcpp", unload = TRUE)
> library(kernlab)
Error: package or namespace load failed for ‘kernlab’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/blah/Library/R/4.0/library/kernlab/libs/kernlab.so':
dlopen(/Users/blah/Library/R/4.0/library/kernlab/libs/kernlab.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
Referenced from: /Users/blah/Library/R/4.0/library/kernlab/libs/kernlab.so
Reason: image not found
> detach("package:kernlab", unload = TRUE)
Error in detach("package:kernlab", unload = TRUE) :
invalid 'name' argument
I'm running on MacOS 11.2.3 and recently updated XCode (12.4) and CommandLineTools - this seemed to break a few things so I suspect there may be a connection. R is version 4.0.4 and RStudio is version 1.4.1106.
How do I go about trying to fix this?
I fixed this by using brew to uninstall R and Rstudio and reinstalling - but it only worked if I installed R from the cask, although the versions of R and RStudio remained the same.
The main difference I can see is that my new Makeconf file has a -mmacosx-version-min=10.13 flag set for CC, CXX, CXX11 etc (compiler is clang).

Error in dyn.load(file, DLLpath = DLLpath, ...)

I am trying to install Deseq2, however I get this error. The same appears for all other packages I try to install with BiocLite...I wonder what is the problem? I installed R and rstudio with anaconda on my ubuntu 16.04. R version 3.3.2. Any help is much appreciated.
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/dani/anaconda2/lib/R/library/tidyr/libs/tidyr.so':
/home/dani/anaconda2/lib/R/library/tidyr/libs/tidyr.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/dani/anaconda2/lib/R/library/tidyr’
* restoring previous ‘/home/danianaconda2/lib/R/library/tidyr’
does it has something to do with this error at the beginning?
Makevars:21: Makevars.local: No such file or directory
touch: "Makevars.local"
I know this is not the best solution: I was using anaconda version 4.3.1 and I changed it to 4.1.1 and reinstalled all using this version, R remained always v 3.3.2. So I don't know if there is a bug or some incompatibility problem with Rcpp package or else in the last version of conda.

Installing Bioconductor highthroughputassays workflow gives rgl errors and fail to load

When I try to install the bioconductor workflow 'highthroughputassays' as follows (and as described here):
> source("http://bioconductor.org/workflows.R")
> workflowInstall("highthroughputassays")
It installs a lot of dependent packages, but just before ending the installation it gives the following errors:
No man pages found in package ‘highthroughputassays’
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rgl', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so':
dlopen(/Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so, 6): Library not loaded: /opt/X11/lib/libGLU.1.dylib
Referenced from: /Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so
Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/johansenkh/Library/R/3.3/library/highthroughputassays’
Warning in install.packages :
installation of package ‘highthroughputassays’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/hb/sc3x6vtj0ys009qnyplbp2_h1g5hgm/T/RtmpDkWkRH/downloaded_packages’
Because of those errors, the workflow does not load;
library(flowStats)
gives a similar error after installing packages as described above.
I have tried it on 3 different Mac computers (all with the newest OS X, but one of them had the 3.3.1 version of R (The newest version is 3.3.2))
When trying library(rgl) I get the following error:
Error : .onLoad failed in loadNamespace() for 'rgl', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so':
dlopen(/Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so, 6): Library not loaded: /opt/X11/lib/libGLU.1.dylib
Referenced from: /Users/johansenkh/Library/R/3.3/library/rgl/libs/rgl.so
Reason: image not found
Error: package or namespace load failed for ‘rgl’
I solved the problem as follows:
The problem was with loading 'rgl'.
By installing XQUARTZ (www.XQUARTZ.com) followed by restarting OS X (Log out and log in) the rgl-package worked. Thereafter the workflow installed as indicated above.

Resources