Closed floswald closed 5 years ago
devtools::install_github
. I get the same when installing directly from source.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.
> 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
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.
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
.
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.
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?
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.
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
.
@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.
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)
tidycensus imports tigris imports rgdal.
Maybe using importFrom("tidycensus", ...)
for code, and selective namespace use in examples and vignettes can suppress creeping imports. Which of your repos contains USfert?
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.
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!
I had a similar problem as documented here: https://github.com/OSGeo/PROJ/issues/1572.
I can build from source and
sf
loads correclty. also, simple commands withproj
work on my commandline. I get thepj_obj_create: Cannot find proj.db
error whenever I build the package from source, not when I use the CRAN version.My package loads fine after that:
but computations involving
st_distance
displaypj_obj_create: Cannot find proj.db
Originally posted by @floswald in https://github.com/r-spatial/sf/issues/1055#issuecomment-496476331