`rinstalled` for Keeping Your Packages When Updating R22 May 2018
When we update
R to a new version, the packages you downloaded for the previous version won’t get loaded. Some code has been dispersed to take care of this, but there are so notably shortcomings to this.
- It doesn’t work if some of the packages were not downloaded from CRAN (e.g., GitHub).
- You need to do this before updating. People like me don’t always think ahead when they see a new version of
I wrote a quick package that helps with this. It currently only works on Mac unless you tell it where the packages are downloaded (up to and including the “Versions” folder). From there, the package will do the heavy lifting for you. It helps you determine which of your packages were downloaded from CRAN and which were from another source. It also helps simplify the code.
So let’s say we just updated our
R to version
3.5.0. Let’s install devtools so we can install
rinstalled (it isn’t available on CRAN yet).
From there, we load
rinstalled, use the
installed_cran() function that gives us the formerly installed packages and versions that are available on CRAN with the argument
updated = TRUE. The argument tells
R that we already updated it so it should look for the updated packages in the version right below the newest. From there, we grab the
Package column and turn it into a character vector and assign it to
packages. We can then give
install.packages() the vector and it will do the rest for us.
There is also a function to see the package-version combinations not available on CRAN. Both the
installed_cran() and the
installed_not_cran() provide a data.frame with a column with the package name (
Package) and version (
Hope this helps ease the transition to new versions of