1

This is a small pet peeve. I'm reading a latin1 encoded shapefile in R using st_read and the encoding option.

I just found out that if I write encoding=latin1 everything works as expected but, if I write encoding = latin1 I get a warning message and the encoding is not set correctly.

Is this the expected behavior? Has anyone else noticed this?

1
  • 1
    I can't replicate this behaviour with a shapefile of my own. Can you post the whole sequence of commands you've used?
    – obrl_soil
    Jan 15, 2019 at 11:49

1 Answer 1

2

These options are passed to the device driver and so are subject to GDAL/OGR driver syntax rules. You don't provide an example but I reckon this is what you are doing:

> s = st_read("./crop.shp", options="encoding=latin1", quiet=TRUE)

> s = st_read("./crop.shp", options="encoding = latin1", quiet=TRUE)
Warning message:
In CPL_read_ogr(dsn, layer, as.character(options), quiet, type,  :
  GDAL Message 6: driver ESRI Shapefile does not support open option encoding 

Why? Because that's the way it is. I suspect its because GDAL maybe supports options as flags for some of the drivers, but this parameter needs a value and so has to be key=value with no spaces.

1
  • That's exactly what I was doing. So it looks like it't just how GDAL works. Will keep an eye for extra spaces when using st_read...
    – Daniel
    Jan 15, 2019 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.