Need to re-install packages every time I start R in RStudio

I've just updated my RStudio to version 1.4.1717 and R to version 4.1.0 (18 May 2021). Now, every time I start a new project, I need to re-install the package again. Trying library() returns Error in library(meta) : there is no package called ‘meta’

Is this a bug to the recent version? Or am I missing something?

Update note: If I try to re-install a package, all previously installed packages will be re-installed instead. I have to re-download every packages I have installed and it took quite a long time before the console is idle again, let alone the increasing data usage.

Thank you very much in advance.

Best,
Gilbert

Hi @gilbertlzrus,
Every time you upgrade R by a major or minor version (e.g. 3.6 to 4.0, or 4.0 to 4.1) a new user package library is created. All the packages that you previously used need to be downloaded and reinstalled - a bit of a pain but at least you get all the latest versions!

# Current library paths (user and system)
.libPaths()

# Find user libraries of previous versions of R
# This works on Windows not sure about Mac/Linux
list.dirs("~/R/win-library/", recursive=FALSE)

# OK, get a character vector of names of those packages installed in user 
# library of old version. e.g.
old_list <- as.data.frame(installed.packages(
                          lib.loc="path_to_your_old/R/win-library/3.6"))
old_list$Package

# Re-install those packages in the user library for the new version
install.packages(old_list$Package)

HTH

Thank you very much for the answer. If I re-install the packages using your code lines, will I get the latest version of the packages? Thanks for the help. Will mark your answer as the solution

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.