首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:包是由一个R版本安装的,有不同的内部;它需要重新安装

错误:包是由一个R版本安装的,有不同的内部;它需要重新安装
EN

Stack Overflow用户
提问于 2018-05-02 23:35:35
回答 1查看 3.5K关注 0票数 3

我遇到了一个软件包安装问题,在那里,我完全不知道如何管理的情况。

代码语言:javascript
复制
install.packages("C:/Users/Oliver/Downloads/NPRED.zip", repos = NULL, type = "win.binary")
Installing package into ‘C:/Users/Oliver/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
package ‘NPRED’ successfully unpacked and MD5 sums checked
library("NPRED", lib.loc="~/R/win-library/3.5")

*

代码语言:javascript
复制
> Error: package or namespace load failed for ‘NPRED’:
>      package ‘NPRED’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version

*

有人能帮我解决那个问题吗?

非常感谢!干杯,奥利

EN

回答 1

Stack Overflow用户

发布于 2022-01-29 11:41:15

代码语言:javascript
复制
# Find the currently installed packages, put this in a data frame
df_all_packages <- as.data.frame(installed.packages())

看看这个,检查哪个主要和次要的R版本在那里。

代码语言:javascript
复制
View(df_all_packages)
table(df_all_packages$Built) # how many packages built under each version of R

下面的示例假设您使用R4并希望基于R3.6升级一些包。你应该根据你自己的情况调整一下。

代码语言:javascript
复制
# Find older package versions, make a list with packages which are of older version and you want to update
df_packages_to_upgrade <- as.data.frame(subset(df_all_packages, (Built %in% c('3.6.1', '3.6.2','3.6.3'))))
# Or you can prefer to base the filtering on those you want to keep, if so uncomment next line:
# df_packages_to_upgrade <- as.data.frame(subset(df_all_packages, !(Built %in% c('4.0.1', '4.0.2','4.0.3'))))

# Finally re-install the packages :
install.packages(df_packages_to_upgrade$Package)

有时候,上面提到的都会失败。特定包的依赖项可能会发生更改,这可能很难跟踪;这可能涉及到棘手的OS级依赖关系。在一种情况下,我不得不:

代码语言:javascript
复制
# At bash command line, as root:
yum install jq-devel protobuf-devel libcurl-devel openssl-devel geos-devel gdal gdal-devel proj-devel proj-nad proj-epsg libjpeg-turbo*
# use 'apt-get install' on Debian-based
# Then, in R (as linux super-user), remove all old packages - but before, make a copy-paste of the list, just in case
# The list:
old_packages_removed <- rownames(df_packages_to_upgrade)

remove.packages(df_packages_to_upgrade$Package)
# Then I installed the 2 or 3 packages I really needed, which ended up installing 50 packages (most of the previously un-installed ones)
# You could try, instead:
install.packages(old_packages_removed)

这为我解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50144957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档