R packages are not generally compatible across upgrades and must be reinstalled after updating R. This inclusive tutorial covers the reinstallation steps of available R packages. Find out how to reinstall all packages after updating R.

Managing R packages is important part for the data scientist working with R since lots of tools are available in separate R packages. Firstly, we will learn how to get a list of installed packages. In second step, we pull the name of packages available in R. Then, we will learn how to save the name of the packages. After that, you can update R. Then, we learn to pull the names of packages in R console. At last, we go over how to reinstall all packages in R.

We can see the installed packages with installed.packages() function.

packages <- as.data.frame(installed.packages())
rownames(packages) <- NULL

Check Out: How to List Installed Packages with Versions in R

After we obtained the list of install packages, we pull the names of packages.

out <- packages[,"Package"]

Let’s see the head of the package names available in R.

head(out)
## [1] "A3" "ABCanalysis" "abind" "ada" "admisc" "AER"

Also Check: How to Install and Load a Package in R

In this part, we save the names of the packages available in R with write.table() function.

write.table(out, file = "Package_List.txt", sep = "\t", row.names = FALSE, col.names = FALSE)

Also Check: How to Clean Data in R

Then, we can update our R programme. After we have the new version of R, we need to read the names of R packages we saved in .txt file. We read the package names with read.table() function.

List <- read.table("Package_List.txt")

The class of List object is data frame having just one column which is the package names. Let’s see the head of the package names.

head(List[,1])
## [1] "A3" "ABCanalysis" "abind" "ada" "admisc" "AER"

At last, we can install multiple R packages with install.packages() function.

install.packages(List[,1], repos = "https://cloud.r-project.org")

The application of the codes is available in our youtube channel below.

How to Reinstall All Packages After Updating R
Subscribe to YouTube Channel

Don’t forget to check: Missing Data Imputations in R – Mean, Median, Mode


Dr. Osman Dag