首页 > 解决方案 > R:从 3.5 降级到 3.4 后无法安装软件包。dyn.load 中的错误(文件,DLLpath = DLLpath,...)

问题描述

我已经按照此处的详细说明安装了 R 3.5.1 ,但是我对某些软件包(即rJavaand )有一些问题XML,所以我决定卸载 R 3.5.1 并从 Ubuntu 18.04 存储库降级到 R 3.4.4。

我成功地做到了,但是现在,当我尝试在 R 中重新安装任何 CRAN 包时,例如:

install.packages("ggplot2")
library(ggplot2)

我收到以下错误:

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 

任何线索如何解决这个问题?谢谢

标签: rggplot2packageinstallation

解决方案


好的,如果有人感兴趣,这个删除所有用户安装包的脚本就像一个魅力。它是从这里取来的。

# 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)

推荐阅读