Download STATS19 data for a year or range of two years.

dl_stats19(year = NULL, type = NULL, data_dir = tempdir(),
  file_name = NULL, ask = TRUE)

Arguments

year

Single year for which file is to be downloaded.

type

One of 'Accidents', 'Casualties', 'Vehicles'; defaults to 'Accidents'. Or any variation of to search the file names with such as "acc" or "accid".

data_dir

Parent directory for all downloaded files. Defaults to tempdir().

file_name

The file name (DfT named) to download.

ask

Should you be asked whether or not to download the files? TRUE by default.

Details

This function downloads and unzips UK road crash data. It results in unzipped .csv files that are put in the temporary directory specified by tempdir() or provided data_dir.

The file downloaded would be for a specific year (e.g. 2017). It could also be a file containing data for a range of two (e.g. 2005-2014).

The dl_* functions can download many MB of data so ensure you have a sufficient internet access and hard disk space.

See also

Examples

dl_stats19(year = 2017) # interactively select files...
#> More than one file found, selecting the first.
#> Files identified: dftRoadSafetyData_Vehicles_2017.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/dftRoadSafetyData_Vehicles_2017.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpGajYm7/dftRoadSafetyData_Vehicles_2017/Veh.csv
# now you can read-in the data dl_stats19(year = 2009)
#> More than one file found, selecting the first.
#> Files identified: DfTRoadSafety_Accidents_2009.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/DfTRoadSafety_Accidents_2009.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpGajYm7/DfTRoadSafety_Accidents_2009/DfTRoadSafety_Accidents_2009.csv
dl_stats19(year = 2009, type = "casualties")
#> Files identified: DfTRoadSafety_Casualties_2009.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/DfTRoadSafety_Casualties_2009.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpGajYm7/DfTRoadSafety_Casualties_2009/DfTRoadSafety_Casualties_2009.csv
dl_stats19(type = "casualties")
#> More than one file found, selecting the first.
#> 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/RtmpGajYm7/dftRoadSafetyData_Casualties_2017/Cas.csv
dl_stats19(year = 1985)
#> Year not in range, changing to match 1979:2004 data
#> This will download 240 MB+ (1.8 GB unzipped).
#> Coordinates unreliable in this data.
#> Files identified: Stats19-Data1979-2004.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/Stats19-Data1979-2004.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpGajYm7/Stats19-Data1979-2004/Vehicles7904.csv/tmp/RtmpGajYm7/Stats19-Data1979-2004/Road-Accident-Safety-Data-Guide-1979-2004.xls/tmp/RtmpGajYm7/Stats19-Data1979-2004/Casualty7904.csv/tmp/RtmpGajYm7/Stats19-Data1979-2004/Accidents7904.csv