简体   繁体   English

如何在安装旧版本的R后恢复R包?

[英]How to restore R packages after installing an old version of R?

There's a package that's only working under a old R version (2.15.3), so I installed this version but sharply find I lost all the installed packages (~100). 有一个软件包只能在旧的R版本(2.15.3)下工作,所以我安装了这个版本,但是我发现我丢失了所有已安装的软件包(~100)。 I am using MAC OS X 10.8 and wondering is there a way to restored all the previously installed packages? 我正在使用MAC OS X 10.8,并想知道有没有办法恢复以前安装的所有软件包?

This was the easiest approach I found when I upgraded from 2.15 to 3.0. 这是我从2.15升级到3.0时发现的最简单的方法。 Code is from here . 代码来自这里 You can do this after you install R 3.0, because your 2.15 package library will still exist (as long as you don't uninstall it): 您可以在安装R 3.0之后执行此操作,因为您的2.15软件包库仍然存在(只要您不卸载它):

# Get list of installed packages for R 2.15
package_df <- as.data.frame(installed.packages("/Library/Frameworks/R.framework/Versions/2.15/Resources/library"))
package_list <- as.character(package_df$Package)

# Re-install the packages to your new version
install.packages(package_list)

It looks like you want to go from a newer version to an older version, so just put in the correct path to the packages for your current version then use that list to install them in the version you're switching to. 看起来您想要从较新版本转到旧版本,因此只需为当前版本输入正确的路径,然后使用该列表将其安装到您要切换到的版本中。 If you store your packages in a different directory, just point to whatever directory you use. 如果将软件包存储在其他目录中,只需指向您使用的目录即可。 If you want to check where R stores your packages, use .libPaths() . 如果要检查R存储包的位置,请使用.libPaths()

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

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