Home > other >  Cannot download "raster" package in R Studio-
Cannot download "raster" package in R Studio-

Time:11-18

I am trying to use the raster package in R but since I bought a new computer and have the latest version of R on macOS it mentions certain packages are not available for this version of R.

I tried downloading R directly on R studio and that gave me errors.

Next I tried installing directly from GitHUB using the following command: install.packages('raster', repos='https://rspatial.r-universe.dev')

and this is the error message I receive:

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

Installing package into ‘/Users/username/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
also installing the dependency ‘terra’

Packages which are only available in source form, and may need compilation of
  C/C  /Fortran: ‘terra’ ‘raster’
Do you want to attempt to install these from sources? (Yes/no/cancel) yes
installing the source packages ‘terra’, ‘raster’

trying URL 'https://rspatial.r-universe.dev/src/contrib/terra_1.6-43.tar.gz'
Content type 'application/x-gzip' length 1777090 bytes (1.7 MB)
==================================================
downloaded 1.7 MB

trying URL 'https://rspatial.r-universe.dev/src/contrib/raster_3.6-6.tar.gz'
Content type 'application/x-gzip' length 1310884 bytes (1.3 MB)
==================================================
downloaded 1.3 MB

* installing *source* package ‘terra’ ...
** using staged installation
configure: CC: clang -arch arm64
configure: CXX: clang   -arch arm64 -std=gnu  11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘terra’
* removing ‘/Users/username/Library/R/arm64/4.2/library/terra’
Warning in install.packages :
  installation of package ‘terra’ had non-zero exit status
ERROR: dependency ‘terra’ is not available for package ‘raster’
* removing ‘/Users/username/Library/R/arm64/4.2/library/raster’
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/zp/vysqcnr95g5d08jhlmzrvj9m0000gn/T/Rtmpn4J6eA/downloaded_packages’

When I load raster next this is what I see:

library(raster)
#Error: package or namespace load failed for ‘raster’ in #loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
# there is no package called ‘terra’

I really need the raster package urgently. Please help

CodePudding user response:

Make sure you have Rtools installed on your system (click here). Then try the following steps:

1- When you open RStudio, right-click on the icon and choose `Run as Administrator.

2- Temporarily deactivate your firewall or antivirus.

3- Use the following commands:

install.packages('raster', dependencies=TRUE, repos='https://CRAN.R-project.org/')
library(raster)

See if the problem is solved.

CodePudding user response:

Can you edit your question and show what happens when you run

install.packages('terra')
install.packages('raster')

I would not install from source code if you do not have to. But if you must, first install "terra". See https://github.com/rspatial/terra for instructions about installing from source code.

  • Related