Download STATS19 data for a year
Usage
dl_stats19(
year = NULL,
type = NULL,
data_dir = get_data_directory(),
file_name = NULL,
ask = FALSE,
silent = FALSE
)
Arguments
- year
A year matching file names on the STATS19 data release page e.g.
2020
- type
One of 'Accident', 'Casualty', 'Vehicle'; defaults to 'Accident'. 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.
Examples
# \donttest{
if(curl::has_internet()) {
# type by default is accidents table
dl_stats19(year = 2017)
# try another year
dl_stats19(year = 2018)
}
#> More than one file found, selecting the first.
#> Files identified: dft-road-casualty-statistics-casualty-2017.csv
#> https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-casualty-2017.csv
#> Attempt downloading from: https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-casualty-2017.csv
#> More than one file found, selecting the first.
#> Files identified: dft-road-casualty-statistics-casualty-2018.csv
#> https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-casualty-2018.csv
#> Attempt downloading from: https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-casualty-2018.csv
#> NULL
# }