Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st_write with '~' in path gives error #456

Closed
yeedle opened this issue Aug 4, 2017 · 8 comments
Closed

st_write with '~' in path gives error #456

yeedle opened this issue Aug 4, 2017 · 8 comments

Comments

@yeedle
Copy link

yeedle commented Aug 4, 2017

Providing a path to st_write (on linux) that includes the ~ as a shorthand for the home directory gives an error. st_read doesn't result in the same error.

library(sf)
#> Linking to GEOS 3.5.0, GDAL 2.1.0, proj.4 4.9.2, lwgeom 2.3.2 r15302

nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/home/yeedle/R/x86_64-pc-linux-gnu-library/3.4/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID):    4267
#> proj4string:    +proj=longlat +datum=NAD27 +no_defs

st_write(nc, '~/nc.geojson')
#> Warning in CPL_write_ogr(obj, dsn, layer, driver,
#> as.character(dataset_options), : GDAL Error 4: Failed to create GeoJSON
#> datasource: ~/nc.geojson.
#> Creating dataset ~/nc.geojson failed.
#> Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), : Creation failed.

st_write(nc, '/home/yeedle/nc.geojson')
#> Writing layer `nc' to data source `/home/yeedle/nc.geojson' using driver `GeoJSON'
#> features:       100
#> fields:         14
#> geometry type:  Multi Polygon

st_read('~/nc.geojson')
#> Reading layer `OGRGeoJSON' from data source `/home/yeedle/nc.geojson' using driver `GeoJSON'
#> Simple feature collection with 100 features and 14 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID):    4267
#> proj4string:    +proj=longlat +datum=NAD27 +no_defs
Session info ``` sessionInfo() #> R version 3.4.1 (2017-06-30) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: elementary OS 0.4.1 Loki #> #> Matrix products: default #> BLAS: /usr/lib/libblas/libblas.so.3.6.0 #> LAPACK: /usr/lib/lapack/liblapack.so.3.6.0 #> #> locale: #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] sf_0.5-4 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.12 digest_0.6.12 rprojroot_1.2 grid_3.4.1 #> [5] DBI_0.7 backports_1.1.0 magrittr_1.5 evaluate_0.10 #> [9] units_0.4-5 stringi_1.1.5 rmarkdown_1.6 tools_3.4.1 #> [13] udunits2_0.13 stringr_1.2.0 yaml_2.1.14 compiler_3.4.1 #> [17] htmltools_0.3.6 knitr_1.16 ```
@edzer
Copy link
Member

edzer commented Aug 18, 2017

Indeed, this is linux-only; in addition, st_write's second argument dsn often is not a file, but for instance a database descriptor. Why not play it safe yourself and use

st_write(nc, normalizePath('~/nc.geojson'))

?

@edzer edzer closed this as completed Aug 25, 2017
@zross
Copy link

zross commented Jul 30, 2018

Hi Edzer, this is a year old but I'm just putting in my two cents. I do think this will be confusing for most users. I'm experienced with the package and yet I just spent 15 minutes problem solving on this one until I found this issue. normalizePath() will not be a function that an average user of the package will be familiar with and they will likely want to use something like "~/junk/myfile.shp" given that this works fine with most writing from R.

@edzer edzer reopened this Aug 6, 2018
@edzer edzer closed this as completed in 1368cc2 Aug 6, 2018
@edzer
Copy link
Member

edzer commented Aug 6, 2018

Thanks - should work now!

@zross
Copy link

zross commented Aug 7, 2018

Great! I'll give it a try. I think this will help simplify the process for many Mac users.

@mwip
Copy link

mwip commented Jan 29, 2019

I still experience this on Arch Linux.

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libblas.so.3.8.0
LAPACK: /usr/lib/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] dplyr_0.7.8  raster_2.8-4 sp_1.3-1     sf_0.6-3  

@jsta
Copy link
Contributor

jsta commented Jan 29, 2019

@mwip Your sf package version is somewhat old (its from last May). Maybe try upgrading?

@mwip
Copy link

mwip commented Jan 29, 2019

@jsta Thanks for the immediate response. Actually forgot to update.

@jimrpy
Copy link

jimrpy commented Mar 31, 2019

@edzer Thanks, this method is quite awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants