ropensci/stats19

Casualties and sf output format

Closed this issue · 1 comments

Another thing that I did not consider is the following:

# packages
library(stats19)
#> Data provided under OGL v3.0. Cite the source and link to:
#> www.nationalarchives.gov.uk/doc/open-government-licence/version/3/

get_stats19(2017, type = "casualties", output_format = "sf")
#> Files identified: dftRoadSafetyData_Casualties_2017.zip
#>    http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/dftRoadSafetyData_Casualties_2017.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpU0Y2L0/dftRoadSafetyData_Casualties_2017/Cas.csv
#> 0 rows removed with no coordinates
#> Warning: Length of logical index must be 1 or 170993, not 0
#> Error in getClassDim(rep(0, length(coords)), length(coords), dim, "POINT"): 0 is an illegal number of columns for a POINT

Created on 2020-02-18 by the reprex package (v0.3.0)

The problem occurs here

stats19/R/get.R

Lines 171 to 179 in f9982ed

# transform read_in into the desired format
if (output_format != "tibble") {
read_in = switch(
output_format,
"data.frame" = as.data.frame(read_in, ...),
"sf" = format_sf(read_in, ...),
"ppp" = format_ppp(read_in, ...)
)
}

since it doesn't make sense to use format_sf for casualities. Should I create a test for this case and create and informative error message?

I think a message and returning a data frame would be the best option. Well spotted!