简体   繁体   中英

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). I am using MAC OS X 10.8 and wondering is there a way to restored all the previously installed packages?

This was the easiest approach I found when I upgraded from 2.15 to 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):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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