[R-sig-Geo] proj.db can't be found when rgdal is loaded (sometimes)

Christian John cjohn @end|ng |rom ucd@v|@@edu
Mon Sep 14 20:07:01 CEST 2020


Hi there folks,

I am running into problems using sf objects when rgdal has been loaded.
When I run:

Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
ROI1 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI1)
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

everything plots fine. The sf startup message is:

Linking to GEOS 3.8.1, GDAL 3.1.2, PROJ 7.1.1

The PROJ_LIB changes upon loading rgdal from "" to
"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj".
Loading rgdal generates the message:

Loading required package: sp
rgdal: version: 1.5-16, (SVN revision 1050)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
Path to GDAL shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
GDAL binary built with GEOS: FALSE
Loaded PROJ runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Linking to sp version:1.4-2
Overwritten PROJ_LIB was
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Warning message:
package ‘rgdal’ was built under R version 3.6.2

which explains the update in the PROJ_LIB. Notably, the gdal and proj
runtime in the rgdal startup message are completely different from the sf
versions. If I run:

Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

which is the same as above, but without the ROI1 generation and plotting, I
get a stack overflow error upon plotting ROI2. All other messages are the
same, except when I run the ggplot() line, I get:

Error: node stack overflow
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
Error during wrapup: node stack overflow

Warnings 1:50 are all

1: In CPL_crs_from_input(x) :
  GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db

So, it seems like loading rgdal before doing anything sf:: related causes
the issue. Any ideas for troubleshooting? Session info can be found below.

Best,
Christian

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_1.5-16        sp_1.3-2            ggplot2_3.3.0
rnaturalearth_0.1.0
[5] sf_0.9-5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3         rstudioapi_0.10    magrittr_1.5       units_0.6-5

 [5] munsell_0.5.0      tidyselect_0.2.5   colorspace_1.4-1
lattice_0.20-38
 [9] R6_2.4.1           rlang_0.4.2        dplyr_0.8.3        tools_3.6.1

[13] grid_3.6.1         gtable_0.3.0       KernSmooth_2.23-15 e1071_1.7-3

[17] DBI_1.0.0          withr_2.1.2        rgeos_0.5-5        class_7.3-15

[21] assertthat_0.2.1   lifecycle_0.1.0    tibble_2.1.3       crayon_1.3.4

[25] purrr_0.3.3        glue_1.3.1         compiler_3.6.1     pillar_1.4.3

[29] scales_1.1.0       classInt_0.4-2     pkgconfig_2.0.3

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list