R packages "raster" fail to upload while searching for "terra" last version

Viewed 2933

I'm working in Windows 10 with R 4.1.2 in RStudio 2021.09.2. I'm working with spatial data, both vectors and rasters, but three days ago the command library(raster) started to gave me this warning:

Error: package or namespace load failed for ‘raster’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): namespace ‘terra’ 1.4-22 loaded, but >= 1.5.12 is required

  • I tried to update terra, the update finished successfully but the version remains 1.4-22.
  • I tried also to remove the packages (terra, raster, sf), then install again everything, but the error remains.
  • Finally, I tried the following:
require(devtools)
install_version("terra", version = "1.5-12", repos = "https://cran.r-project.org/src/contrib/Archive/terra/terra_1.5-12.tar.gz")

but in the end the version is the same, 1.4-22. I tried again:

packageurl <- "https://cran.r-project.org/src/contrib/Archive/terra/terra_1.5-12.tar.gz"

install.packages(packageurl, repos=NULL, type="source")

And nothing changed, unfortunately. Is anyone experimenting something similar? How could I fix this error, in your opinion? There are a lot of packages based on terra and I got stuck because seems that none of them can work without this update. Thank you for your help!

3 Answers

Thank you to all the kind persons who tried to answer.

I finally fixed the problem by:

  • restarting R in a clean new session

  • removing terra package

  • quitting R, then restarting again

  • installing the package terra asking for the development version:

    install.packages('terra', repos='https://rspatial.r-universe.dev')

Have you tried to update terra directly through R Studio interface, on the "Packages" tab? I was facing the same issue but managed to fix it by doing so.

I had the same issue. I was able to solve doing the following steps:

  1. Download and install RTools: https://cran.r-project.org/bin/windows/Rtools/rtools40.html

  2. Open RStudio and run install.packages("terra").

  3. Confirm that you want to install it from source.

  4. Wait while console compile the terra package.

Done! You can now load the raster package.

Related