Failing to load many packages

Hi,
all of a sudden I seem unable to load any package in R.
Using library("ggplot2") or tydiverse, dartR and other packages, i get the following error:

library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): namespace ‘rlang’ 1.0.3 is already loaded, but >= 1.0.6 is required In addition: Warning message: package ‘ggplot2’ was built under R version 4.2.2

I have R version 4.2.1 and until yesterday ggplot2 worked perfectly fine there and no loading issues whatsoever.

--> following suggestions on forum i ran this code:

  1. Remove the rlang package via the function remove.packages().
  2. Restart the R session (Ctrl + Shift+ F10) and then shut RStudio down completely
  3. Reinstall the rlang package via the call: install.packages("rlang", dependencies = TRUE)

But then I got a slightly different error message:

library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
namespace ‘vctrs’ 0.4.1 is already loaded, but >= 0.5.0 is required

I tried to reinstall "vctrs" like this:

install.packages("vctrs", dependencies = TRUE)
Error in install.packages : Updating loaded packages

Restarting R session...
library(vctrs)
packageVersion("vctrs")
[1] ‘0.4.1’

So, I still have the same issue.

I read that they suggest to install new versions of R and RStudio and update all your packages, but 1st that requires a long time and 2nd and most importantly a lot of my code may not work anymore with newer versions of packages as it's often the case, so i want to avoid updating packages especially in such a massive and untargeted way as much as possible.

Any advice on how to solve this issue?
I cannot work on R at all at the moment.

Thanks a lot
Best,
Gabriella

I think the next step is to start a fresh R session and run

install.packages(vctrs)

Then try to run library(tidyverse) again.

1 Like

This almost always means to do as @FJCC suggests whenever such a message appears.

What OS are you running? I guess, if all else fails, uninstall and delete everything, and install the same version of R. To get the same versions of the packages you were using up until, say, the beginning of the month, you could use the Posit package manager, which makes it possible to get packages as they were at a certain date. For example, on Windows you could use this link:

https://packagemanager.rstudio.com/cran/2022-12-01

as the repository, and get packages as of December 1st. You can read more about this here.

But I’d leave this as a last resort solution, and also only if you’re absolutely sure that you cannot update your packages. Depending on what you are doing, updating packages is usually safe. If not, I’d recommend using the posit package manager in the future, or {renv}, or Docker.

Hi everyone,
thank you all for your quick reply. I really appreciated it.

My current operating system is Windows 10 Enterprise.

I managed to fix part of the problem I think by restarting R (as you said @FJCC) and re-installing vtcrs but this time using the following code to specify installation of the version that seemed required (>0.5.0) instead of the one installed with the simple "install.packages("vctrs", dependencies = TRUE)":

Instead I used:
versions::install.versions("vctrs", version="0.5.1", lib = "C:/R/win-library/4.2").

However, I had the following issue -->
<also installing the dependency ‘cli’
trying URL 'https://MRAN.revolutionanalytics.com/snapshot/2022-11-30/bin/windows/contrib/4.2/cli_3.4.1.zip'
Content type 'application/zip' length 1257774 bytes (1.2 MB)
downloaded 1.2 MB
trying URL 'https://MRAN.revolutionanalytics.com/snapshot/2022-11-30/bin/windows/contrib/4.2/vctrs_0.5.1.zip'

Content type 'application/zip' length 1361042 bytes (1.3 MB)
downloaded 1.3 MB
package ‘cli’ successfully unpacked and MD5 sums checked

Warning: cannot remove prior installation of package ‘cli’

Warning: restored ‘cli’

package ‘vctrs’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\scatag\AppData\Local\Temp\RtmpoBjp5m\downloaded_packages

Warning message:
In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Users\AppData\Local\R\win-library\4.2\00LOCK\cli\libs\x64\cli.dll to C:\Users\scatag\AppData\Local\R\win-library\4.2\cli\libs\x64\cli.dll: Permission denied>

So, I deleted cli folder manually from the 4.2 R library and tried again and that worked.

Now, I can load most packages (seems so far at least) but for some I still get the "warning message" that the package was built under R version 4.2.2 (I have 4.2.1):

library(vctrs)
Warning message:
package ‘vctrs’ was built under R version 4.2.2

library(ggplot2)
Warning message:
package ‘ggplot2’ was built under R version 4.2.2

WHY??
I don't understand. Until yesterday I loaded every package including ggplot2 without any issue or warning message. Today, I get these issues.
Plus, i looked at ggplot CRAN link CRAN - Package ggplot2 (r-project.org) and it says that depends on R ≥ 3.3. So, why the warning message about this package being built under R 4.2.2??

I would like to understand what happened between yesterday and today so that i can learn how to avoid these issues again.
Yesterday, the last thing I did before running in this issue was installing the package "ggpubr". Could installing this package have caused all these issues?
I must admit I did not restart R before installing ggpubr as recommended by the pop-up message...did this cause a problem because ggplot2 and other packages were already loaded??

If anyone could direct me into understanding these processes better I would really appreciate it!!
Thank you!!
Now, I just need to test if ggplot2 functions are still working...despite the warning message when loading ggplot2...but it seems they do so far

By the way, thank you so much Brodiguesco for suggesting the Posit package manager. Does it reinstall the exact version of any package you had previously despite the fact that you might have had version of different years for the different packages? Or would it install only all packages versions from a specific date (i.e. latest version of all your previous packages dating December 2021)?

Thanks again a lot!

I see that your repos are using MRAN, at the snapshot from November 11th. I guess this may be the issue, somehow, and I don’t know how, installing ggpubr could have caused some dependency hell situation. These packages require never packages, but because you’re using MRAN at a fixed snapshot, these packages cannot be installed. I’ve had similar issues on Windows and Linux as well. I’m never really able to reproduce them, so I’m not entirely sure what’s going on. But usually, removing all the library and reinstalling the packages fixes it. On Windows, because packages are compiled, installation is quite fast.

Regarding your question, the posit package manager works similarly to what you’re already using; MRAN. It installs the packages from the internet at a fixed date.

Ideally, to avoid issues like this in the future, you might want to use {renv}, which installs a per-project library. Introduction to renv • renv
This way, you install the required packages per project, and can use older or newer versions of packages for other projects. The different libraries don’t interfere with each other.

@ishtar_dory
One further note - the warning about packages built under 4.2.2 appears because a new version of R was released and all the packages on CRAN and other good repositories get compiled using that R version. If you are running an earlier R version, that warning is printed. That is rarely a problem. The longer you go without updating your R, the more likely that it will become a problem but I don't recall ever experiencing that myself. You will have to pick an update strategy that works for you.

1 Like

This topic was automatically closed 42 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.