Closed maxl-amberg closed 7 months ago
We need your output of
sessionInfo()
Sys.getenv("PROJ_LIB")
Sys.getenv("PROJ_DATA")
Sys.getenv("GDAL_DATA")
How did you install sf
? CRAN binary, CRAN source with CRAN recipes static libraries, or otherwise?
Thanks for the quick answers!
I already provided the session info under "details" (see above). Apart from that, the remaining outputs are as follows:
> Sys.getenv("PROJ_LIB")
[1] ""
> Sys.getenv("PROJ_DATA")
[1] ""
> Sys.getenv("GDAL_DATA")
[1] ""
I simply installed the sf
package via install.packages("sf")
and also tried renv:install("sf")
.
Yes, but did you install the binary package from a CRAN mirror (which mirror?) or did you install the source package? Use for example type="binary"
because if you got a source package, you might get a failed install if you also have PROJ, GDAL and GEOS also installed on your platform by something else.
I see.
Regarding the CRAN mirror currently used:
> getOption("repos")["CRAN"]
CRAN
"https://packagemanager.posit.co/cran/latest"
My default is the type is the following:
> getOption("pkgType")
[1] "both"
I have just removed the sf
package again and tried install::packages("sf", type = "binary")
, but this did not help – probably because "both"
already implies ‘use binary if available and current, otherwise try source’
.
That still does not tell us whether your sf
came from a binary or a source install. What does it tell you when you install it? What's the extension of the downloaded file?
Sorry about that.
I am getting the following information:
install.packages("sf")
yields:
The following package(s) will be installed:
- sf [1.0-15]
These packages will be installed into "~/workdir/repos/github_private/transport_project/renv/library/R-4.2/aarch64-apple-darwin20".
Do you want to proceed? [Y/n]: Y
# Installing packages --------------------------------------------------------
- Installing sf ... OK [linked from cache]
Successfully installed 1 package in 8.3 milliseconds.
install.packages("sf", type = "both")
and install.packages("sf", type = "binary")
both yield:
Installing package into ‘/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.2/aarch64-apple-darwin20’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.posit.co/cran/latest/bin/macosx/big-sur-arm64/contrib/4.2/sf_1.0-15.tgz'
Content type 'binary/octet-stream' length 19277046 bytes (18.4 MB)
==================================================
downloaded 18.4 MB
The downloaded binary packages are in
/var/folders/tn/psl2yx_50ml1lr1zm43m11080000gn/T//RtmpTcuxs1/downloaded_packages
Lastly, install.packages("sf", type = "source")
yields:
Installing package into ‘/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.2/aarch64-apple-darwin20’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/sf_1.0-15.tar.gz'
Content type 'binary/octet-stream' length 3544759 bytes (3.4 MB)
==================================================
downloaded 3.4 MB
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: clang -arch arm64
configure: CXX: clang++ -arch arm64 -std=gnu++14
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.2/aarch64-apple-darwin20/sf’
The downloaded source packages are in
‘/private/var/folders/tn/psl2yx_50ml1lr1zm43m11080000gn/T/RtmpPJK3FK/downloaded_packages’
Warning message:
In utils::install.packages("sf", type = "source") :
installation of package ‘sf’ had non-zero exit status
I hope this is what you need. Please let me know if not.
You are apparently using R 4.2. Avoid at all costs the Posit mirror and renv
, they are the joint suspect until proven innocent. Download https://cran.r-project.org/bin/macosx/big-sur-arm64/contrib/4.2/sf_1.0-15.tgz manually and install manually from the command line (shell prompt) in regular R outside RStudio. If sf
loads correctly in your (outdated) R 4.2, and example(st_crs)
runs, you have located the problem (Posit mirror, Posit package systems, possibly Posit-built binary ignoring the need to build binary with extra configure arguments on Windows and macOS static builds).
Why avoid Posit? If you use CRAN builds, they are tested intensively very often. Posit does not test, or not often, and support for 4.2 may be patchy. Anyway better to upgrade now to R 4.3.3 just released, and to R 4.4 when it is released, most likely next month. Your macOS is probably a good deal younger than R 4.2.2.
Thanks. I have just upgraded to R 4.3.3.
However, renv::install("sf", type = "binary")
now yields:
# Downloading packages -------------------------------------------------------
- Downloading sf from CRAN ... ERROR [error code 22]
Error: error downloading 'https://packagemanager.posit.co/cran/latest/src/contrib/sf_1.0-15.tgz' [error code 22]
Also renv::install("sf", type = "source")
ends with an error:
# Downloading packages -------------------------------------------------------
- Downloading sf from CRAN ... OK [file is up to date]
- Downloading units from CRAN ... OK [file is up to date]
Successfully downloaded 2 packages in 0.17 seconds.
The following package(s) will be installed:
- sf [1.0-15]
- units [0.8-5]
These packages will be installed into "~/workdir/repos/github_private/transport_project/renv/library/R-4.3/aarch64-apple-darwin23.2.0".
Do you want to proceed? [Y/n]: Y
# Installing packages --------------------------------------------------------
- Installing units ... FAILED
Error: Error installing package 'units':
=================================
* installing *source* package ‘units’ ...
** package ‘units’ successfully unpacked and MD5 sums checked
** using staged installation
configure: units: 0.8-5
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C++... yes
checking whether clang++ -std=gnu++17 accepts -g... yes
checking for clang++ -std=gnu++17 option to enable C++11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for _Bool... no
checking for stdbool.h that conforms to C99... yes
checking for error_at_line... no
checking for gcc... clang
checking whether the compiler supports GNU C... yes
checking whether clang accepts -g... yes
checking for clang option to enable C11 features... none needed
checking for XML_ParserCreate in -lexpat... yes
checking for udunits2.h... no
checking for udunits2/udunits2.h... no
checking for ut_read_xml in -ludunits2... no
configure: error: in `/private/var/folders/tn/psl2yx_50ml1lr1zm43m11080000gn/T/RtmpTn4tT4/R.INSTALL1013b283316a7/units':
configure: error:
--------------------------------------------------------------------------------
Configuration failed because libudunits2.so was not found. Try installing:
* deb: libudunits2-dev (Debian, Ubuntu, ...)
* rpm: udunits2-devel (Fedora, EPEL, ...)
* brew: udunits (OSX)
If udunits2 is already installed in a non-standard location, use:
--configure-args='--with-udunits2-lib=/usr/local/lib'
if the library was not found, and/or:
--configure-args='--with-udunits2-include=/usr/include/udunits2'
if the header was not found, replacing paths with appropriate values.
You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------
See `config.log' for more details
ERROR: configuration failed for package ‘units’
* removing ‘/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/staging/1/units’
install of package 'units' failed [error code 1]
Same if install.packages()
is used with type = "binary"
or type = "source"
.
My advice: try another CRAN mirror, try not using renv, try install binaries.
Thanks for your advice!
Unfortunately, install.packages("sf", type = "binary", repos = "https://cran.r-project.org")
also yields:
# Downloading packages -------------------------------------------------------
- Downloading sf from CRAN ... ERROR [error code 22]
Error: error downloading 'https://cran.r-project.org/src/contrib/sf_1.0-15.tgz' [error code 22]
No idea how you get there: that file does not exist. Looking at the landing page of sf on CRAN, the file you should be downloading is https://cran.r-project.org/bin/macosx/big-sur-arm64/contrib/4.3/sf_1.0-15.tgz (for r-release).
Not sure whether homebrew has a problem with newer versions of R (see here). This is why I uninstalled R via homebrew and installed R 4.3.3 for MacOS the usual way again. In my fresh setup, getOption("repos")["CRAN"]
still gives me
CRAN
"https://packagemanager.posit.co/cran/latest"
while getOption("pkgType")
yields "both"
.
Using install.packages("sf", type = "binary", repos = "https://cran.r-project.org")
allows me to download/install the file you are referring to:
Installing package into ‘/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.3/aarch64-apple-darwin20’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/bin/macosx/big-sur-arm64/contrib/4.3/sf_1.0-15.tgz'
Content type 'application/x-gzip' length 86909904 bytes (82.9 MB)
==================================================
downloaded 82.9 MB
The downloaded binary packages are in
/var/folders/tn/psl2yx_50ml1lr1zm43m11080000gn/T//Rtmpv0V214/downloaded_packages
However, I am still getting the initially posted warning and error messages when using st_read()
to load and geom_sf()
to plot the shapefile.
@rsbivand: Could the problem be associated with the use of tmap (as you suspected here some time ago)? As mentioned initially, the warning and error occurred after I installed and used tmap for the first time.
By the way, example(st_crs)
yields:
st_crs> sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs> sf = st_sf(a = 1:2, geom = sfc)
st_crs> st_crs(sf) = 4326
st_crs> st_geometry(sf)
Geometry set for 2 features
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1
CRS: NA
POINT (0 0)
POINT (1 1)
st_crs> sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs> st_crs(sfc) = 4326
st_crs> sfc
Geometry set for 2 features
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1
CRS: NA
POINT (0 0)
POINT (1 1)
st_crs> sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs> sfc %>% st_set_crs(4326) %>% st_transform(3857)
Error in st_transform.sfc(., 3857) :
cannot transform sfc object with missing crs
In addition: Warning messages:
1: In CPL_crs_from_input(x) :
GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db
2: In CPL_crs_from_input(x) :
GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db
3: In CPL_crs_from_input(x) :
GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db
@edzer: The proj.db file is located in /Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.3/aarch64-apple-darwin20/sf/proj
.
Since Sys.getenv("PROJ_LIB")
yields ""
, do I need to set it via Sys.setenv("PROJ_LIB")
manually? Unfortunately, Sys.setenv(PROJ_LIB = "/Users/maxl-amberg/workdir/repos/github_private/transport_project/renv/library/R-4.3/aarch64-apple-darwin20/sf/proj")
does not change anything.
Have you tried doing all this without renv
, as I suggested above?
Yes, I have tried it (but literally 10 min. ago). It worked out outside of my project in which I am using renv.
Outside of the renv-managed project, the setup is as follows:
> getOption("repos")["CRAN"]
CRAN
"https://cran.rstudio.com/"
> getOption("pkgType")
[1] "both"
> Sys.getenv("PROJ_LIB")
[1] ""
> Sys.getenv("PROJ_DATA")
[1] ""
> Sys.getenv("GDAL_DATA")
[1] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/sf/gdal"
So Sys.getenv("GDAL_DATA")
is not empty. Does this mean that within renv-managed projects Sys.setenv(GDAL_DATA = "...")
has to be set manually?
Does this mean that within renv-managed projects Sys.setenv(GDAL_DATA = "...") has to be set manually?
You tell me. To me it tells that renv
is the cause of your problem. See also this thread: https://mastodon.social/@joranelias/112039358805771553
Similar to: https://github.com/rstudio/renv/issues/1832
Why avoid Posit? If you use CRAN builds, they are tested intensively very often. Posit does not test, or not often, and support for 4.2 may be patchy. Anyway better to upgrade now to R 4.3.3 just released, and to R 4.4 when it is released, most likely next month. Your macOS is probably a good deal younger than R 4.2.2.
Just debugged this problem in a different context and leaving a note for other people whom a search engine directs here in the future. The contents of the following two files are not idential:
Specifically, the one from Posit package manager is missing two subfolders proj
and gdal
which explains many of these problems.
On macOS, when building binary packages not being installed on the same file system, the configure argument --with-data-copy=yes
needs to be used to copy the GDAL and PROJ metadata files into the built package. On Windows this is handled by Makefile.ucrt
. Could someone who understands the posit package manager please alert them to this requirement (also applies to other packages with PROJ or GDAL as system requirements)?
Hi all,
I seem to have a problem related to
proj.db
and the setting ofPROJ_LIB
.Description: When using
st_read()
, I am getting the following warning:As a consequence, using
geom_sf()
yields the following error:Repex The warning and error occur no matter which shapefile I load and regradless of the shapefile I want to plot. (For instance, I encountered it when loading Eurostat's NUTS 3 shapefile).
Additional context I have other software installed that might set the environment variable
PROJ_LIB
: Since I have last usedst_read()
andgeom_sf()
in my R project, I installed Anaconda, Python and VS Code to create a conda environment (incl.geopandans
, etc.) to run Python via VS Code. However, I do not use conda for R. Instead, I use therenv
package in my R project. Apart from that, I am not sure whether the upgrade fromsf_1.0-14
tosf_1.0-15
or the installation oftmap
might cause the issue. Lastly, runningSys.unsetenv("PROJ_LIB")
at the beginning of the script does not do the trick.Many thanks in advance!