Error Loading Packages...I think?

Hi!

I'm working on a school assignment and I loaded my data set and now I'm trying to run the following:

uncomment install.packages("caret") if already installed

install.packages("caret")

library(caret)

but I keep getting the following error message:
Error: package or namespace load failed for ‘caret’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
namespace ‘cli’ 3.3.0 is already loaded, but >= 3.4.0 is required

I have tried updating packages, uninstalling/reinstalling packages, I'm not sure what to do here. Can anyone please help?

Thanks!

This tells you to re-install an outdated dependency with

install.packages("cli")

Thanks for your response. I tried that previously and it didn't work. I just tried to install again, and got the same error message when I re-ran the code.

This is actually what comes up when I try to do install.packages(). But I have RTools installed already.

WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/XXXXXXXXXX/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/cli_3.6.0.zip'
Content type 'application/zip' length 1299125 bytes (1.2 MB)
downloaded 1.2 MB

Did you restart R after successfully updating cli?

Hi @teitva,
You're using Windows, so you don't need to build (compile) the package from the source code - just install the latest pre-compiled binary from CRAN. Using this approach rtools is not needed.
Run install.packages("caret", dependencies=TRUE, type="win.binary"),
or use the RStudio pull-down menu in the "Packages" pane and answer "No" if you're asked about installing from source.

1 Like

Whether on Win, Mac or Lin, if presented with the option to install from source, take it once. If it works fine. If it doesn’t, it will never compile for the vast majority of RStudio users who do not devote an appreciable portion of their time to development and are well versed in modifying source code to address situations peculiar to their choice of OS.

The “later source version” temptation can be avoided with a little patience. Binary versions usually do not lag past 10-14 days.

Among Linux distributions, building from source almost always succeeds unless there are missing dependencies on the target. Usually, a little rseeking will uncover the right name to bring in using apt install. Even here, though, the way can be smoother and the trip much shorter by using r2u from Dirk Eddelbuettel, the World’s Foremost Authority™️ on all things at the intersection of R and Debian.

Key features that allow installing all of tidyverse in under 20 seconds after downloading.

  • Full integration with apt as every binary resolves all its dependencies: No more installations (of pre-built archives) only to discover that a shared library is missing. No more surprises.
  • Full integration with apt so that an update of a system library cannot break an R package: if a (shared) library is used by a CRAN, the package manager knows and will not remove it. No more (R package) breakage from (system) library updates.
  • Installations are fast, automated and reversible thanks to package management layer.
  • Fast and well-connected mirror at r2u.stat.illinois.edu on the Internet2
  • Complete coverage with (currently) ~ 20,000 CRAN packages (and 240+ from BioConductor).
  • Complete support for both Ubuntu 20.04 ("focal") and Ubuntu 22.04("jammy").
  • Optional (but recommeded) bspm use automagically connects R functions like install.packages() to apt for access to binaries and dependencies.

The World’s Foremost Authority™️ used in honor of Professor Irwin Corey.

1 Like

Thank you thank you! I don't know what I kept doing wrong, but I ran the install.packages() you suggested, restarted RStudio, and IT WORKED! Phew! Thank you so much!

1 Like

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