简体   繁体   English

r-将旧的r版本软件包复制到包含新版本软件包的新文件夹是否正确?

[英]r - Is it right to copy the old r version packages to the new folder that contains the packages of the new version?

I installed the latest version of r 3.5.0 and copied all the packages, from my old version 3.4.3, and pasted them to the current version folder 3.5 I think this is not a good way to copy and paste the packages because RStudio asks me to reinstall the package that I call. 我安装了最新版本的r 3.5.0,并从旧版本3.4.3复制了所有软件包,并将它们粘贴到当前版本的文件夹3.5中,我认为这不是复制和粘贴软件包的好方法,因为RStudio询问我重新安装该软件包。 For example, it gives me this error when I install zoo: 例如,当我安装zoo时,它给了我这个错误:

Error: package or namespace load failed for ‘zoo’:
package ‘zoo’ was installed by an R version with different internals; it 
needs to be reinstalled for use with this R version

What should I do to copy them the right way? 我应该怎么做才能正确复制它们?

It is much safer to re-build packages for the newer version of R rather than coping them. 为新版本的R重建软件包比解决它们要安全得多。

The easiest way to re-build all the packages, would be to save the list of packages in the old version of R in the file, then load it into the new version of R and install them: 重建所有软件包的最简单方法是将文件列表以旧版本的R保存在文件中,然后将其加载到新版本的R中并安装它们:

# In old version of R:
ip <- installed.packages()[,1]
write(ip,"rpackages_in_3.4.3.txt")
q()

# In new version of R:
ip_3.4.3 <- readLines("rpackages_in_3.4.3.txt")
setRepositories(graphics=FALSE, ind=1:6)
install.packages(ip)

There is also package installr that might be useful for this purpose: https://cran.r-project.org/web/packages/installr/installr.pdf 还有一个软件包安装程序可能对此有用: https : //cran.r-project.org/web/packages/installr/installr.pdf

For Windows at least, and perhaps others, what you have done plus what @Ben Bolker suggests is exactly what the manual says most people should do: 至少对于Windows也许还有其他的Windows,您所做的事情加上@Ben Bolker的建议,正是手册所说的大多数人应该做的事情:

For most people the best thing to do is to [...] copy any installed packages to the library folder in the new installation, run update.packages(checkBuilt=TRUE, ask=FALSE) in the new R and then delete anything left of the old installation. 对于大多数人来说,最好的做法是将所有已安装的软件包复制到新安装中的库文件夹中,在新R中运行update.packages(checkBuilt = TRUE,ask = FALSE),然后删除所有剩余的内容。旧安装。

From: https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f 来自: https : //cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f

However, they also qualify that by saying it is "a matter of taste", so if you find another method that works for you go with that, I just wanted to point out the method you tried is valid and even suggested by the documentation. 但是,他们也通过说这是“一种口味问题”来限定这一点,因此,如果您发现另一种适合您的方法,我只想指出您尝试的方法是有效的,甚至是文档中建议的方法。

UPDATE: I just had R updated on my own system and since I use a fixed location for my packages (ie no version number in the path) I didn't even copy them from one place to another, I only did the update.packages(checkBuilt = TRUE, ask = FALSE) part and it works fine. 更新:我刚刚在自己的系统上更新了R,并且由于我的软件包使用了固定的位置(即路径中没有版本号),所以我什至没有将它们从一个地方复制到另一个地方,所以我只做了update.packages(checkBuilt = TRUE, ask = FALSE)部分,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM