R Version Check
We are getting a new version of R. Yay! According to R-Project, the Version 4.0.0 was released yesterday. I guess I will need to update my R. Let’s check what I am running right now.
paste(version$major, version$minor,sep = ".")
##  "3.6.1"
Yup – I am at 3.6.1 so I definitely need to update. Time to launch my default update script:
Updating R Version
# R Update Script for Windows # eval = FALSE, I am not ready to update yet. install.packages("installr") library(installr) updateR()
However, before I can update, I need to make sure that all my packages will get moved to the new version. So time for a quick bit of code to ensure that.
Saving All Packages
# First save a list of all installed packages packagelist <- installed.packages() # Now save the list to a local file saveRDS(packagelist, "packagelist.rds")
Now we are good to update R version using the code in previous section. Note that if you are using RStudio, it is typically better to call updateR function from raw R session and not from an RStudio session.
Loading Packages in Updated R Version
So you have updated your R version. All went smooth. Now you would want all your packages back. Here you go:
# First read the list of R packages listofpackages <- readRDS("packagelist.rds") # Now install all the packages in the list to the new version install.packages(listofpackages[,1])
That’s it. All your packages would not have moved to your updated R version.