skip to Main Content

I’m trying to install package "raster" in R for spatial analysis and some of the packages, those are not seem bo be installed with "raster – terra, raster, vis, rgdal.

I’ve tried so far:

install.packages("pbkrtes"), 
install.packages("terra", dependencies = TRUE), etc

But it does not go…
Here is the pic of the last attempt.
I have ubuntu 22.04 and R 4.3.2

Would anybody hint me for the solution?

I tried previously what I could find in Stack… didn’t help

enter image description here

2

Answers


  1. Those packages depend on GDAL, GEOS, and PROJ. In the old days, one needed to install these using system commands. (Since you don’t lay out what has been tried previously, we cannot know if you did any of that spadework.) But my understanding is that the sf-package dependencies which is the core of spatial packages, will now orchestrate the installation of those system packages, so you should first try:

    install.packages("rgdal")
    install.packages("rgeos"
    install.packages("sf")
    

    If that fails (and I’m unable to test whether it will succeed since I have a complete version on my Ubuntu 18.04 system), then search SO on the topic of errors in installation of sf and rgdal.

    This website: https://r-spatial.github.io/sf/ recommends this script for system-mediated installation of those dependencies (obviously from a Terminal session):

    sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
    sudo apt-get update
    sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite0-dev
    
    Login or Signup to reply.
  2. As you are on Ubuntu 22.04, you can rely on binaries from r2u. Earlier today I just replied to someone on Mastodon with a similar question for just sf and prepared a demo in a quick mp4 I cannot post here because of the file size limit but you can read the post with its demo or just look at the mp4 video demo.

    It would be the same for your issue — on an Ubuntu system where the r2u apt repo has been added and bspm been added you just do

    install.packages(c("terra", "raster", "vis", "rgdal", "sf"))
    

    I just did in a r2u container and it took all of 25 seconds to install a total of 70 binary .deb packages.

    Edit: To illustrate, for example for package sf we automatically resolve to

    $ root:/# apt-cache show r-cran-sf                                                                                                                                                                      
    Package: r-cran-sf                                  
    Architecture: amd64                                 
    Version: 1.0-12-1.ca2204.1                       
    Priority: optional                                  
    Section: gnu-r                                      
    Maintainer: Dirk Eddelbuettel <[email protected]>
    Installed-Size: 7203                                
    Depends: libc6 (>= 2.32), libgcc-s1 (>= 3.0), libgdal30 (>= 3.4.0), libgeos-c1v5 (>= 3.10.0), libproj22 (>= 7.1.0), libstdc++6 (>= 11), r-base-core (>= 4.2.2), r-api-4.0, r-cran-classint, r-cran-dbi, r-cran-magr
    ittr, r-cran-rcpp, r-cran-s2, r-cran-units          
    Suggests: r-cran-blob, r-cran-covr, r-cran-dplyr, r-cran-ggplot2, r-cran-knitr, r-cran-lwgeom, r-cran-maps, r-cran-mapview, r-cran-matrix, r-cran-microbenchmark, r-cran-odbc, r-cran-pbapply, r-cran-pillar, r-cra
    n-pool, r-cran-raster, r-cran-rlang, r-cran-rmarkdown, r-cran-rpostgres, r-cran-rpostgresql, r-cran-rsqlite, r-cran-sp, r-cran-spatstat, r-cran-spatstat.geom, r-cran-spatstat.random, r-cran-spatstat.linnet, r-cr
    an-spatstat.utils, r-cran-stars, r-cran-terra, r-cran-testthat, r-cran-tibble, r-cran-tidyr, r-cran-tidyselect, r-cran-tmap, r-cran-vctrs, r-cran-wk
    Filename: pool/dists/jammy/main/r-cran-sf_1.0-12-1.ca2204.1_amd64.deb
    Size: 3075194                                       
    MD5sum: 8cb3721102e9b1051e3020c52b8a6ca3
    SHA1: a53e6f195177a5fadb5ddb5bcabf110d5de8a920
    SHA256: 7eeddaf172251dd9eeaf806b0f5b071bbfc98c22b6feee951c38c6e07c9bc4bf
    SHA512: 3c08529dd9bd9963e2689dc9d9de6291d0e51d8290a20a97f51ec911254871ede030a470be77b5a1fe1d9e02895b0f8ceabb3252f3cbb8c6ccd8d10b83b4894e
    Homepage: https://cran.r-project.org/package=sf
    Description: CRAN Package 'sf' (Simple Features for R)
     Support for simple features, a standardized way to encode spatial vector
     data. Binds to 'GDAL' for reading and writing data, to 'GEOS' for
     geometrical operations, and to 'PROJ' for projection conversions and datum
     transformations. Uses by default the 's2' package for spherical geometry
     operations on ellipsoidal (long/lat) coordinates.
    Description-md5: cb73ad855572663ce996c8621e813bfb
    
    $ root:/#
    

    which shows exactly which graphics libraries are needed and supplied:

    libgdal30 (>= 3.4.0), libgeos-c1v5 (>= 3.10.0), libproj22 (>= 7.1.0)
    

    and ditto with the needed R packages

    r-cran-classint, r-cran-dbi, r-cran-magrittr, r-cran-rcpp,
    r-cran-s2, r-cran-units
    

    each of which of course bring their dependencies in. And best of all: no compilation, no failure, no errors, and near-immediate access.

    Give it a try, you can even try r2u in your browser thanks to https://gitpod.io (if you sign up, eg with your github id). See the link at the end of https://eddelbuettel.github.io/r2u/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search