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

dl_stats19(
  year = NULL,
  type = NULL,
  data_dir = get_data_directory(),
  file_name = NULL,
  ask = FALSE,
  silent = FALSE
)

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.

silent

Boolean. If FALSE (default value), display useful progress messages on the screen.

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 get_data_directory() 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

# \donttest{ dl_stats19(year = 2017) # interactively select files...
#> More than one file found, selecting the first.
#> Files identified: dftRoadSafetyData_Accidents_2017.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/dftRoadSafetyData_Accidents_2017.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpPSYWX6/dftRoadSafetyData_Accidents_2017/Acc.csv
# now you can read-in the data dl_stats19(year = 2009)
#> More than one file found, selecting the first.
#> 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/RtmpPSYWX6/DfTRoadSafety_Casualties_2009/DfTRoadSafety_Casualties_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
#> Data already exists in data_dir, not downloading
#> Data saved at /tmp/RtmpPSYWX6/DfTRoadSafety_Casualties_2009/DfTRoadSafety_Casualties_2009.csv
dl_stats19(type = "casualties")
#> More than one file found, selecting the first.
#> Files identified: DfTRoadSafety_Casualties_2019.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/DfTRoadSafety_Casualties_2019.zip
#> Attempt downloading from:
#> Data saved at /tmp/RtmpPSYWX6/DfTRoadSafety_Casualties_2019/Road Safety Data - Casualties 2019.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 and other variables may be unreliable in these datasets.
#> See https://github.com/ropensci/stats19/issues/101 and https://github.com/ropensci/stats19/issues/102
#> 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/RtmpPSYWX6/Stats19-Data1979-2004/Vehicles7904.csv/tmp/RtmpPSYWX6/Stats19-Data1979-2004/Road-Accident-Safety-Data-Guide-1979-2004.xls/tmp/RtmpPSYWX6/Stats19-Data1979-2004/Casualty7904.csv/tmp/RtmpPSYWX6/Stats19-Data1979-2004/Accidents7904.csv
# }