Skip to content

Commit

Permalink
Do not use curl::has_internet(), close #255
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Jan 14, 2025
1 parent 2eb6dc9 commit 9021113
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 2 additions & 12 deletions R/dl.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,12 @@ dl_stats19 = function(year = NULL,
stop("Stopping as requested", call. = FALSE)
}
}
# Save to tempfile first, to avoid partial downloads
tmp_file = tempfile()
# Check to see if zip_url is a valid URL with the curl package:
if (!curl::has_internet()) {
message("No internet connection detected. Please check your connection and try again.")
return(NULL)
}
if (isFALSE(silent)) {
message("Attempt downloading from: ", zip_url)
}
res = curl::curl_fetch_disk(zip_url, tmp_file)

res = curl::curl_fetch_disk(zip_url, destfile)
if (res$status != 200) {
message("Failed to download file: ", zip_url)
return(NULL)
}
file.rename(tmp_file, destfile)
if (isFALSE(silent)) {
message("Data saved at ", destfile)
}
Expand Down
8 changes: 7 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ You can install the released version of stats19 from [CRAN](https://cran.r-proje
install.packages("stats19")
```

Load the development version of the package from this repository with:

```{r eval=FALSE}
devtools::load_all()
```

## get_stats19()

`get_stats19()` requires `year` and `type` parameters, mirroring the provision of STATS19 data files, which are categorised by year (from 1979 onward) and type (with separate tables for crashes, casualties and vehicles, as outlined below).
The following command, for example, gets crash data from 2022 (**note**: we follow the "crash not accident" campaign of [RoadPeace](https://www.roadpeace.org/working-for-change/crash-not-accident/) in naming crashes, although the DfT refers to the relevant tables as 'accidents' data):

```{r}
crashes = get_stats19(year = 2022, type = "collision")
crashes = get_stats19(year = 2023, type = "collision")
```

What just happened?
Expand Down

0 comments on commit 9021113

Please sign in to comment.