R update on Mac

Asked

Viewed 199 times

1

How do I update R and Rstudio, but without losing the packages I already own?

Mac usage

1 answer

1


Depending on the type of update to be made, there is no need to reinstall any package in R. For example, if the update is from version 3.x.0 to 3.x.1 (that is, if the second number is constant), just update R and Rstudio and then run the command update.packages().

On the other hand, every update minor R (for example, going from version 3.5.y to 3.6.1) requires packages to be reinstalled, regardless of the operating system. This is because R installs the packages in a directory named after the version minor installed. For example, for versions 3.6.0 onwards, the default folder is

/Library/Frameworks/R.framework/Versions/3.6/Resources/library

Note that the string 3.6 is in the directory path above. You can find out where your packages are installed by running the command .libPaths().

A not too painful way to update R and reinstall all packages that are already installed is as follows:

  1. Turn the command pacotes <- unname(installed.packages(lib.loc = .libPaths())[, "Package"]) to see which packages are installed on your machine

  2. Save the name of these packages to a file on disk with the command write.csv(pacotes, file = "~/Desktop/pacotes.csv")

  3. After R and Rstudio have been updated, run the two lines below to reinstall the packages automatically

    pacotes <- read.csv(file = "~/Desktop/pacotes.csv")

    install.packages(pacotes[, 2], dependencies = TRUE)

The drawback of this method is that only packages available in CRAN will be installed. Bioconductor, github, Rforge or similar packages will be left out.

  • Thank you, Marcus. You helped me a lot. Hug.

  • It’s great to know that my response has helped you in some way. So consider vote and accept the answer, so that in the future other people who experience the same problem have a reference to solve it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.