ropensci/stats19

2020 vehicles data

ds221 opened this issue · 3 comments

ds221 commented

Hi when running:
gb2020_veh_dl <- get_stats19(year = 2020, type = "vehicle")
I see

Multiple matches. Which do you want to download?

1: dft-road-casualty-statistics-vehicle-2020.csv
2: dft-road-casualty-statistics-vehicle-e-scooter-2020.csv

Selection: 1
Files identified: dft-road-casualty-statistics-vehicle-2020.csv

   https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-vehicle-2020.csv
Attempt downloading from: https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-vehicle-2020.csv
trying URL 'https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-vehicle-2020.csv'
Content type 'application/vnd.ms-excel' length 15532260 bytes (14.8 MB)
==================================================
downloaded 14.8 MB

 not found
Try running dl_stats19(), change arguments or try later.FALSE
Error in names(x) <- new_names : attempt to set an attribute on NULL

'casualty' and 'accident' are OK

ds221 commented

Hi could you advise please if there is a workaround to this issue I can usually locally until it is fixed? Thanks.

Hi! Sorry for the late comment. I fear that, for the moment, you can only use a "manual" approach to get stats19 vehicle data for 2020 from the gov website. For example:

# 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/
library(readr)

# get data
vehicle_2020 <- read_delim("https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-vehicle-2020.csv")
#> Rows: 167375 Columns: 27
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> chr  (3): accident_index, accident_reference, generic_make_model
#> dbl (24): accident_year, vehicle_reference, vehicle_type, towing_and_articul...
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.

# format data
stats19:::format_stats19(vehicle_2020, type = "Vehicle")
#> # A tibble: 167,375 x 27
#>    accident_index accident_year accident_reference vehicle_referen~ vehicle_type
#>    <chr>                  <dbl> <chr>                         <dbl> <chr>       
#>  1 2020010219808           2020 010219808                         1 Car         
#>  2 2020010220496           2020 010220496                         1 Car         
#>  3 2020010228005           2020 010228005                         1 Car         
#>  4 2020010228006           2020 010228006                         1 Taxi/Privat~
#>  5 2020010228011           2020 010228011                         1 Car         
#>  6 2020010228012           2020 010228012                         1 Car         
#>  7 2020010228014           2020 010228014                         1 Car         
#>  8 2020010228014           2020 010228014                         2 Car         
#>  9 2020010228017           2020 010228017                         1 Car         
#> 10 2020010228017           2020 010228017                         2 Car         
#> # ... with 167,365 more rows, and 22 more variables:
#> #   towing_and_articulation <chr>, vehicle_manoeuvre <chr>,
#> #   vehicle_direction_from <chr>, vehicle_direction_to <chr>,
#> #   vehicle_location_restricted_lane <chr>, junction_location <chr>,
#> #   skidding_and_overturning <chr>, hit_object_in_carriageway <chr>,
#> #   vehicle_leaving_carriageway <chr>, hit_object_off_carriageway <chr>,
#> #   first_point_of_impact <chr>, vehicle_left_hand_drive <chr>, ...

Created on 2021-12-05 by the reprex package (v2.0.1)

I'm not 100% sure that the codes are still valid after recent problems in stats19, so you should double-check the result.

That was useful @agila5. Saluti!