Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

package

r

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. For example, it gives me this error when I install 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?

like image 222
ezzeddin Avatar asked May 02 '18 12:05

ezzeddin


People also ask

Do I need to reinstall packages after updating R?

"On most single-user systems (Mac, Windows, and Linux), when you upgrade to a new minor version of R (like 3.3. 0 to 3.4. 0), R will not find the packages, you will need to reinstall your R packages.

What is the correct way to install the packages in R?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.


2 Answers

It is much safer to re-build packages for the newer version of R rather than coping them.

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:

# 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_3.4.3)

There is also package installr that might be useful for this purpose: https://cran.r-project.org/web/packages/installr/installr.pdf

like image 65
Katia Avatar answered Oct 04 '22 17:10

Katia


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:

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.

From: 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 (i.e. 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.

like image 38
Brian Stamper Avatar answered Oct 04 '22 16:10

Brian Stamper