Cannot install or load packages on R

I tried to install the RcppEigen package, but an error occurred, indicating that RStudio can't open URL. I can't install other packages either in RStudio.

# install
install.packages("RcppEigen")

# error message
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘RcppEigen’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.2:
  cannot open URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.2/PACKAGES'

I just updated my R version, so all the packages are manually copied to the new library. When I try to load a previously installed package, an error occurred again like this:

# load a package
library(StanHeaders)

# error message
Error: package or namespace load failed for ‘StanHeaders’:
 .onLoad failed in loadNamespace() for 'RcppParallel', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/libs/RcppParallel.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/libs/RcppParallel.so, 0x0006): Library not loaded: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libR.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/libs/RcppParallel.so
  Reason: tried: '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file)

Hoping someone can help with the two problems! Thanks!

This seems like a connectivity issue, R is not being able to connect to the CRAN repository you have selected, these are some things to try.

  • Choose a different CRAN repository, RStudios repository is a good choice (http://cran.rstudio.com/) or you could choose one that is geographically closer to you.

  • Disable the secure download setting.

  • Check if your internet connection has traffic restrictions of some kind, like a firewall, proxy server, etc. This is usually the case when you are at work or school.

After a major R version upgrade, you need to update all your packages so all of them are compiled for your current R version, you can update them with this command

update.packages(checkBuilt = TRUE)

But you need to solve your connectivity issues for this to work.

Thank you very much for your advice! Really happy that my problems solved.

Disabling the secure download setting helps. Changing the CRAN repo does not help, since the mirror can't be connected.

Then I found that it would be more convenient to add ask = FALSE as in update.packages(checkBuilt = TRUE, ask = FALSE), so the function can update the packages automatically without asking.

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.