mountainMath / cancensus

R wrapper for calling CensusMapper APIs
https://mountainmath.github.io/cancensus/index.html
Other
82 stars 15 forks source link

Catch rgdal error and try the other way if so #107

Closed dshkol closed 7 years ago

dshkol commented 7 years ago

Stopgap fix for #96 - We can also do it the other way around if people prefer?

mountainMath commented 7 years ago

We could also use tryCatch. Not sure what the best practices are in exception handling in R.

stations = tryCatch({
  readOGR("stations.geojson", "stations")
}, error = function(e) {
  readOGR("stations.geojson", "OGRGeoJSON")
})
dshkol commented 7 years ago

We could also use tryCatch. Not sure what the best practices are in exception handling in R.

Changed. That's a bit more concise and spares an instruction.

Also, it would be cleaner if we store the plain file name without extension earlier so that we can use it in both instances. Maybe call it geo_base_name and use it in geo_file and also in the rgdal call. In case we ever change the way we download and cache files it's all in one place.

Not sure if I follow here, but feel free to make that change to this branch cause I'm not sure where the best place to make that change is.