r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.33k stars 293 forks source link

build from source: `Cannot find proj.db` error with st_distance #1060

Closed floswald closed 5 years ago

floswald commented 5 years ago

I can build from source and sf loads correclty. also, simple commands with proj work on my commandline. I get the pj_obj_create: Cannot find proj.db error whenever I build the package from source, not when I use the CRAN version.

> devtools::install_github("r-spatial/sf",force=TRUE)
Using GitHub PAT from envvar GITHUB_PAT
Downloading GitHub repo r-spatial/sf@master
from URL https://api.github.com/repos/r-spatial/sf/zipball/master
Installing sf
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ  \
  --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/ry/d__dq69j6w31gmbnhz7ybj013sn99p/T/Rtmp4dSvRZ/devtoolsef2e1f2951df/r-spatial-sf-7ac7e7e'  \
  --library='/Library/Frameworks/R.framework/Versions/3.5/Resources/library'  \
  --install-tests 

* installing *source* package ‘sf’ ...
configure: CC: gcc-9
configure: CXX: clang++ -std=gnu++11
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.4.1
checking GDAL version >= 2.0.1... yes
checking for gcc... gcc-9
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 we are using the GNU C compiler... yes
checking whether gcc-9 accepts -g... yes
checking for gcc-9 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc-9 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking gdal.h usability... yes
checking gdal.h presence... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/local/Cellar/gdal/2.4.1_1/share/gdal/pcs.csv readable... yes
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... yes
configure: pkg-config proj exists, will use it
checking proj.h usability... yes
checking proj.h presence... yes
checking for proj.h... yes
configure: PROJ: 6.1.0
checking for proj_context_create in -lproj... yes
checking for geos-config... /usr/local/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.7.2
checking GEOS version >= 3.4.0... yes
checking geos_c.h usability... yes
checking geos_c.h presence... yes
checking for geos_c.h... yes
checking geos: linking with -L/usr/local/Cellar/geos/3.7.2/lib -lgeos_c... yes
configure: Package CPP flags:  -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include
configure: Package LIBS: -L/usr/local/Cellar/proj/6.1.0/lib -lproj   -L/usr/local/Cellar/gdal/2.4.1_1/lib -lgdal -L/usr/local/Cellar/geos/3.7.2/lib -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
** libs
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:948:1: warning: unused variable 'stop_sym' [-Wunused-variable]
BEGIN_RCPP
^
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/macros/macros.h:36:17: note: expanded from macro
      'BEGIN_RCPP'
    static SEXP stop_sym = Rf_install("stop");                                                   \
                ^
RcppExports.cpp:948:1: warning: unused variable 'nprot' [-Wunused-variable]
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/macros/macros.h:32:9: note: expanded from macro
      'BEGIN_RCPP'
    int nprot = 0;                                                                               \
        ^
RcppExports.cpp:984:1: warning: unused variable 'nprot' [-Wunused-variable]
BEGIN_RCPP
^
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/macros/macros.h:32:9: note: expanded from macro
      'BEGIN_RCPP'
    int nprot = 0;                                                                               \
        ^
RcppExports.cpp:984:1: warning: unused variable 'stop_sym' [-Wunused-variable]
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/macros/macros.h:36:17: note: expanded from macro
      'BEGIN_RCPP'
    static SEXP stop_sym = Rf_install("stop");                                                   \
                ^
4 warnings generated.
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c bbox.cpp -o bbox.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c gdal.cpp -o gdal.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c gdal_geom.cpp -o gdal_geom.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c gdal_read.cpp -o gdal_read.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c gdal_utils.cpp -o gdal_utils.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c gdal_write.cpp -o gdal_write.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c geos.cpp -o geos.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c hex.cpp -o hex.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c ops.cpp -o ops.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c polygonize.cpp -o polygonize.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c proj.cpp -o proj.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c proj_info.cpp -o proj_info.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c raster2sf.cpp -o raster2sf.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c sfg.cpp -o sfg.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c signed_area.cpp -o signed_area.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c stars.cpp -o stars.o
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/Cellar/proj/6.1.0/include -DHAVE_PROJ_H -I/usr/local/Cellar/gdal/2.4.1_1/include -I/usr/local/Cellar/geos/3.7.2/include -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c wkb.cpp -o wkb.o
clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o sf.so RcppExports.o bbox.o gdal.o gdal_geom.o gdal_read.o gdal_utils.o gdal_write.o geos.o hex.o ops.o polygonize.o proj.o proj_info.o raster2sf.o sfg.o signed_area.o stars.o wkb.o -L/usr/local/Cellar/proj/6.1.0/lib -lproj -L/usr/local/Cellar/gdal/2.4.1_1/lib -lgdal -L/usr/local/Cellar/geos/3.7.2/lib -lgeos_c -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.5/Resources/library/sf/libs
** R
** demo
** inst
** tests
** byte-compile and prepare package for lazy loading
in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial”
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (sf)

My package loads fine after that:

> library(USfert)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: sf
Linking to GEOS 3.7.2, GDAL 2.4.1, PROJ 6.1.0
Loading required package: ggplot2
Warning messages:
1: package ‘dplyr’ was built under R version 3.5.2 
2: replacing previous import ‘data.table::last’ by ‘dplyr::last’ when loading ‘USfert’ 
3: replacing previous import ‘data.table::first’ by ‘dplyr::first’ when loading ‘USfert’ 
4: replacing previous import ‘data.table::between’ by ‘dplyr::between’ when loading ‘USfert’ 

but computations involving st_distance display pj_obj_create: Cannot find proj.db

Originally posted by @floswald in https://github.com/r-spatial/sf/issues/1055#issuecomment-496476331

floswald commented 5 years ago
  1. none of this happens when using the CRAN version.
  2. I got a very fast patch to my issue in #1055 and wanted to install from source.
  3. this has got nothign to do with devtools::install_github. I get the same when installing directly from source.
  4. I get the correct results, but the warning really slows down things.
  5. here is a typical output from a session where this happens.
Browse[2]> st_distance(tr_centroids[tr_centroids$CZ==cs,],
+             CZ_centroids_empl[CZ_centroids_empl$CZ==cs,],
+             by_element = TRUE)
pj_obj_create: Cannot find proj.db
Units: [m]
  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [22] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [43] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [64] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [85] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[106] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[127] NA NA NA NA NA NA NA
Browse[2]> tr_centroids[tr_centroids$CZ==cs,]
Simple feature collection with 133 features and 11 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 861334.9 ymin: -673958.5 xmax: 960693.5 ymax: -486790.5
epsg (SRID):    NA
proj4string:    +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs
pj_obj_create: Cannot find proj.db
# A tibble: 133 x 12
   GEOID    CZ MSA                    geometry dist_CZ_empl
   <chr> <dbl> <chr>               <POINT [m]>        <dbl>
 1 0100…    60 Mont…        (887531 -517371.3)           NA
 2 0100…    60 Mont…      (889116.1 -517531.8)           NA
 3 0100…    60 Mont…      (890330.5 -517286.6)           NA
 4 0100…    60 Mont…      (891908.8 -517511.3)           NA
 5 0100…    60 Mont…      (894006.6 -518774.9)           NA
 6 0100…    60 Mont…      (888973.4 -521104.4)           NA
 7 0100…    60 Mont…        (892645.8 -522457)           NA
 8 0100…    60 Mont…      (884898.8 -524790.1)           NA
 9 0100…    60 Mont…      (884797.8 -511191.2)           NA
10 0100…    60 Mont…        (882556.3 -499289)           NA
# … with 123 more rows, and 7 more variables: dist_CZ_pop <dbl>,
#   dist_CZ_dens <dbl>, dist_CZ_dens_emp <dbl>, dist_MSA_empl <dbl>,
#   dist_MSA_pop <dbl>, dist_MSA_dens <dbl>, dist_MSA_dens_emp <dbl>

Browse[2]> CZ_centroids_empl[CZ_centroids_empl$CZ==cs,]
Simple feature collection with 1 feature and 1 field (with 1 geometry empty)
geometry type:  POINT
dimension:      XY
bbox:           xmin: NA ymin: NA xmax: NA ymax: NA
epsg (SRID):    NA
proj4string:    +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs
pj_obj_create: Cannot find proj.db
# A tibble: 1 x 2
     CZ         out
  <dbl> <POINT [m]>
1    60       EMPTY

notice that CZ_centroids_empl[CZ_centroids_empl$CZ==cs,] being EMPTY is the reasaon for the output being NA, as expected.

  1. It does not happen on the example from the docs:
> b0 = st_polygon(list(rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1))))
> b1 = b0 + 2
> b2 = b0 + c(-0.2, 2)
> x = st_sfc(b0, b1, b2)
> a0 = b0 * 0.8
> a1 = a0 * 0.5 + c(2, 0.7)
> a2 = a0 + 1
> a3 = b0 * 0.5 + c(2, -0.5)
> y = st_sfc(a0,a1,a2,a3)
> x
Geometry set for 3 features 
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: -1.2 ymin: -1 xmax: 3 ymax: 3
epsg (SRID):    NA
proj4string:    NA
POLYGON ((-1 -1, 1 -1, 1 1, -1 1, -1 -1))
POLYGON ((1 1, 3 1, 3 3, 1 3, 1 1))
POLYGON ((-1.2 1, 0.8 1, 0.8 3, -1.2 3, -1.2 1))
> y
Geometry set for 4 features 
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: -0.8 ymin: -1 xmax: 2.5 ymax: 1.8
epsg (SRID):    NA
proj4string:    NA
POLYGON ((-0.8 -0.8, 0.8 -0.8, 0.8 0.8, -0.8 0....
POLYGON ((1.6 0.3, 2.4 0.3, 2.4 1.1, 1.6 1.1, 1...
POLYGON ((0.2 0.2, 1.8 0.2, 1.8 1.8, 0.2 1.8, 0...
POLYGON ((1.5 -1, 2.5 -1, 2.5 0, 1.5 0, 1.5 -1))
> st_distance(x,y)
          [,1] [,2] [,3]     [,4]
[1,] 0.0000000  0.6    0 0.500000
[2,] 0.2828427  0.0    0 1.000000
[3,] 0.2000000  0.8    0 1.220656
edzer commented 5 years ago

Searching for the error message led me here: https://github.com/pyproj4/pyproj/issues/176 . Setting env variable PROJ_LIB to the directory where proj.db lives, before starting R, would be my first attempt. If this works, next thing we need to sort out is whether this is a PROJ responsibility, or an sf responsibility.

floswald commented 5 years ago

good idea. I tried that, didn't change. i did this

➜  sf git:(master) ✗ export PROJ_LIB=/usr/local/Cellar/proj/6.1.0/share/proj/proj.db
➜  sf git:(master) ✗ R CMD INSTALL .

and also put it in ~/.Renviron.

edzer commented 5 years ago

IIRC, it should be set to the directory, not the file; pls try

export PROJ_LIB=/usr/local/Cellar/proj/6.1.0/share/proj

in the same process where you are going to run R.

floswald commented 5 years ago

good point! didn't work. however, i noticed something:

➜  USfert git:(master) ✗ export PROJ_LIB=/usr/local/Cellar/proj/6.1.0/share/proj
➜  USfert git:(master) ✗ vim ~/.Renviron

so I put the same var into Renviron, then i start R from this shell and I get the same result as above. However, before turning off R I do this:

> Sys.getenv("PROJ_LIB")
[1] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rgdal/proj"

which is clearly not what I set. what's going on here?

rsbivand commented 5 years ago

In a different setting, I've had to Sys.setenv(PROJ_LIB=) before calls to tmap methods in an Rmd document, so the context does seem to matter. Running chunks manually succeeds without PROJ_LIB, but knitting doesn't. Only tried on Fedora 29, should not affect CRAN Windows or OSX binaries because they ship with the set PROJ_LIB on load (sf and rgdal) - both test against proj/nad.lst which maybe should be revisited for subsequent PROJ.

rsbivand commented 5 years ago

So it looks as though your R session has loaded the CRAN OSX rgdal binary, and its setting is overwriting your initial value of PROJ_LIB.

edzer commented 5 years ago

@floswald could you try running a test that sets PROJ_LIB=/usr/local/Cellar/proj/6.1.0/share/proj, runs R, and only loads package sf (and NOT rgdal), then do e.g. library(sf); st_crs(4326)?

@rsbivand I guess the advice now needs to be for OSX: either install sf and rgdal both from source, or both from binary, but don't mix, for the (transition) period where binaries have old PROJ and source installs using brew have PROJ 6.1.0.

floswald commented 5 years ago

yes i think we are on the right track here. what you suggest works (notice that always worked, in the sense that loading sf by it's own always worked). the PROJ_LIB is overwritten as @rsbivand says by something that happens when I load my package (I did not know that I have an rgdal dependency at all!) . I post my DESCRIPTION at the bottom, maybe you know what depends on rgdal here?

> library(sf); st_crs(4326)
Linking to GEOS 3.7.2, GDAL 2.4.1, PROJ 6.1.0
Coordinate Reference System:
  EPSG: 4326 
  proj4string: "+proj=longlat +datum=WGS84 +no_defs"
> Sys.getenv("PROJ_LIB")
[1] "/usr/local/Cellar/proj/6.1.0/share/proj"
> library(USfert)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: ggplot2
Loading required package: doSNOW
Loading required package: foreach
Loading required package: iterators
Loading required package: snow
Warning messages:
1: package ‘dplyr’ was built under R version 3.5.2 
2: replacing previous import ‘data.table::last’ by ‘dplyr::last’ when loading ‘USfert’ 
3: replacing previous import ‘data.table::first’ by ‘dplyr::first’ when loading ‘USfert’ 
4: replacing previous import ‘data.table::between’ by ‘dplyr::between’ when loading ‘USfert’ 
> Sys.getenv("PROJ_LIB")
[1] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rgdal/proj"

DESCRIPTION

Depends: 
    dplyr,
    sf,
    ggplot2,
    doSNOW
Imports: 
    tidycensus,
    pander,
    stargazer,
    ggExtra,
    lfe,
    tibble,
    readr,
    readxl,
    tidyr,
    futile.logger,
    data.table,
    stringr,
    censusapi,
    fasterize

NAMESPACE

export(build_acs)
import(data.table)
import(doSNOW)
import(dplyr)
import(fasterize)
import(futile.logger)
import(ggplot2)
import(sf)
import(stringr)
import(tibble)
import(tidycensus)
edzer commented 5 years ago

tidycensus imports tigris imports rgdal.

rsbivand commented 5 years ago

Maybe using importFrom("tidycensus", ...) for code, and selective namespace use in examples and vignettes can suppress creeping imports. Which of your repos contains USfert?

floswald commented 5 years ago

bingo! removing tigris from namespace imports did the job. the package is private at the moment before we circulate our working paper.

I'll try with the importFrom suggestion.

floswald commented 5 years ago

ok that didn't work. i just leave it out of the imports list for now. as i said, with the CRAN version this problem does not exist. you can close this if you want. thanks for your help!

gdbassett commented 4 years ago

I had a similar problem as documented here: https://github.com/OSGeo/PROJ/issues/1572.