rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
528 stars 87 forks source link

GDAL not linked when installing terra from binaries in renv environment #1290

Open elisehellwig opened 9 months ago

elisehellwig commented 9 months ago

MacOS Ventura 13.5.2 (Apple M2 chip) terra - v. 1.7.46

When I run the following code (terra installed via binaries)

renv::init()

install.packages('terra')
install.packages('geodata')

library('terra')
library('geodata')

usa = gadm('USA', level=, path='data')

usa_ca = project(usa, "epsg:3310")

I get the output/error message

Error: [project] output crs is not valid In addition: Warning message: PROJ: proj_create_from_database: Cannot find proj.db (GDAL error 1)

However, when I install terra from source (code below), it runs with no issues.

renv::init()

install.packages("Rcpp")
install.packages("terra", type = "source", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")
install.packages('geodata')

library('terra')
library('geodata')

usa = gadm('USA', level=1, path='data')

usa_ca = project(usa, "epsg:3310")

It seems like when I install terra from the binaries in the renv environment, terra is unable to find GDAL.

As a note, this is also an issue for raster, but I figured raster compatibility with renv is less of a priority.

iwelch commented 7 months ago

completely new install, desktop ubuntu 23.10. R at 4.3.1, just installed via apt. no local config etc. files.

install.packages("terra") dies for me at

checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.

not sure what gdal is or how to install it. doesn't seem to be an apt package or an R package.

regards,

/iaw

elisehellwig commented 7 months ago

Hi Ivo,

GDAL is a software package that many other programs use to support reading/writing geographic data as well as many geographic transformations. It should be installed automatically with terra, but for some reason that doesn't happen inside an renv virtual environment. You can install it separately (see terra README) but if you aren't installing from source that shouldn't be necessary.

-Elise

iwelch commented 7 months ago

hi elise --- mine was not in a virtual environment...though I am not even sure what this means.  it was in a pure and fresh ubuntu install and a command line invocation of R.

way to fix this was by hand

sudo apt-get install -y libgdal-dev

just trying to help, of course.

wleoncio commented 4 months ago

Installing libgdal-dev worked for me as well (Ubuntu 23.10), but only after removing libmariadb-dev, which was causing some conflicts.