How to update your packages when the new R version comes out? - r

So, anytime a new 3.X R version rolls out my work is stalled because it simply creates a 3.X folder for packages and disregards all the previously installed ones which are in the folder with a previous R version name. I use this workaround:
.libPaths(.libPaths(), "path_to_dir_w_old_packages"), but I have to do it everytime I launch my RStudio. I tried to manually reinstall my packages but as always there are some scientific packages that are old and maintained poorly, so there are no suitable versions for 3.X version (but libs loaded from old dir work just fine). Does anyone by chance know any solution for this annoying incommodity?

Related

Updating R, I do not understand the logic of how R works after updating R to latest version

I've come across a common problem but do not understand the logic of how R works.
So I had R 3.4 and all my libraries were in /usr/local/.../R/3.4 local direction. These libraries were installed using super user admin rights.
I've recently upgraded to R 4.0.0.2, and installed Rstudio, and do not run Rstudio as super user. I've created a new local direction ~/R/x86_ubuntu/4.0 local library.
Now the .libPaths() has the first entry as my local directory, and subsequent paths point to previous library paths.
So if i enter install.packages(foo), the error says,
This package package ‘foo’ was installed before R 4.0.0: please re-install it.Error: package ‘dotCall64’ could not be loaded.'
However I am re-installing the package from source, yet I get the error that I could not re-install it.
I have also tried the install.updates(check=TRUE,ask=FALSE) command and this still gave the same answer.
There are similar posts to this problem, but I just need an explanation as to why this is failing?
Is it because of the library paths conflict? R is trying to load a previous older 3.4 library directory?
This does not make sense because I've downloaded all my 4.0 libraries from source? why is it still pulling from the older versions?
Should I just remove other library paths? Should I delete my old previous library folders?

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. 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?
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
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.

Clarification needed for different approaches to updating R on a mac (and keeping packages)

For over a year now, I've been afraid to update my version of R for fear of losing the "rgdal" package...which when I first started working with R on my mac (and maybe still?), had to be installed from source/ could not be installed via the package installer from within R. That was complicated and I had to seek help from a more experienced R user than myself in order to get this package which is critical for me.
But I've finally decided that I need to take the risk and update R. I used the following instructions:
#--run in the old version of R
setwd("C:/Temp/")
packages <- installed.packages()[,"Package"]
save(packages, file="Rpackages")
Followed by this in the new version:
#--run in the new version
setwd("C:/Temp/")
load("Rpackages")
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p)
found in this post:
Painless way to install a new version of R?
This seems to have worked (e.g. I can open up libraries that aren't included in the base install...including rgdal) but I have the following questions in order to better understand this whole process:
1) Is it the case that in following this approach, I essentially saved a list of all the R packages I had previously installed in my old version, then (from within the new version) determined the SET of packages that differed from the set of base libraries in the new version and told R to install packages belonging to this SET?
2) If the above is true, then does this approach negate the need to update my packages after (e.g. by installing them from within the new version, the newest versions are installed)?
3) The other approach that seems to be common out there (and that is recommended in one of the responses to the post above) is to set up things so that all packages get saved to a directory outside of R and then change the settings (in the .Renviron file or whatever the appropriate file is) to always look for packages in this external directory... I'm wondering why this approach is favoured by some people? Is it because this approach means that after updating R everything is just ready to go (e.g. if one is willing to work with un-updated packages)? I'm confused because if one still has to use update.packages() after installing a new version of R, doesn't this just more or less amount to re-installing them? What are the advantages?
4) Are there packages that I need to worry about if I do go the install route (and not the save to external directory then update route)? R did give me a warning that indicates that four of my packages are not available for the latest version (R. 3.0.3). I'm assuming that if I need to use these packages, I must temporarily just revert to an older version of R. Is this all correct?
Thank you in advance for the help!
1) Yes.
2) The newly installed packages will be at the latest version, but there is no harm in running update.packages(ask=FALSE, checkBuilt=TRUE) afterward just be be sure everything is up to date.
3) I've not seen anyone suggest this particular approach, though a similar process is suggested in the R for Windows FAQ that consists of 1) installing the new version 2) copying the packages from the library folder of the old version to the library folder of the new version and 2) running update.packages(checkBuilt=TRUE, ask=FALSE). I don't think there are any clear advantages to doing it this way vs. the installed.packages()... way.
4) All methods under discussion are limited to CRAN packages, so things that you installed from e.g., bioconductor will not be covered. Also packages removed from CRAN will not be covered, you will either have to use an older version of R or build and install them manually.

How to optimaly upgrade RStudio and R and keep project files and all setup (Windows machine)?

Many people use R and RStudio and they need to keep up with upgrades.
If one wants all RStudio projects to be "remembered". Is is possible? A seamless upgrade of both....
Should one first install new R version and then install RStudio into the same folder. (what is the best order of steps?)
Updating RStudio is no problem. You just go to Help > Check updates in the menu, and RStudio will take care of the rest. It also recognizes the latest installed R version on your computer, so just installing the new R should suffice for that. Note that project files are saved on your computer, and can of course be opened with the new version of RStudio you installed.
Regarding keeping the settings for your R version, see eg:
Painless way to install a new version of R?
Gabor Grothendieck has a package 'batchfiles' on Google Code as well as in CRAN's extra directory which does this.

How to install several versions of R on Mac without overwriting old version?

How do I install multiple versions of R on a Mac without overwriting the old version? Where are the appropriate places to install them?
The most appropriate place would be in the R.framework directory. I have versions dating back to R 2.7 on this machine. Installing of a new version from the binary installation package will not overwrite earlier versions. This is what dragging the symlink "Current Version" folder gives when I drag-drop it into the current console window:
/Library/Frameworks/R.framework/Versions/Current
It's actually a reference to:
/Library/Frameworks/R.framework/Versions/2.15
(This is where the binary installer from CRAN will put successive versions by default if you just click OK to all the dialog boxes during installation.)

Resources