diff --git a/R/get.R b/R/get.R index 7f71b06..ecec0e9 100644 --- a/R/get.R +++ b/R/get.R @@ -36,8 +36,10 @@ #' @examples #' \donttest{ #' if(curl::has_internet()) { -#' x = get_stats19(2022, silent = TRUE, format = TRUE) -#' class(x) +#' col = get_stats19(year = 2022, type = "collision") +#' cas2 = get_stats19(year = 2022, type = "casualty") +#' veh = get_stats19(year = 2022, type = "vehicle") +#' class(col) #' # data.frame output #' x = get_stats19(2022, silent = TRUE, output_format = "data.frame") #' class(x) @@ -97,8 +99,9 @@ get_stats19 = function(year = NULL, silent = FALSE, output_format = "tibble", ...) { - if(!exists("type")) { - stop("Type is required", call. = FALSE) + # Set type to "collision" if it's "accident" or similar: + if (grepl("acc", x = type, ignore.case = TRUE)) { + type = "collision" } if (!output_format %in% c("tibble", "data.frame", "sf", "ppp")) { warning( @@ -130,12 +133,12 @@ get_stats19 = function(year = NULL, silent = silent) read_in = NULL # read in - if(grepl(type, "vehicles", ignore.case = TRUE)){ + if(grepl("veh", x = type, ignore.case = TRUE)){ read_in = read_vehicles( year = year, data_dir = data_dir, format = format) - } else if(grepl(type, "casualty", ignore.case = TRUE)) { + } else if(grepl("cas", x = type, ignore.case = TRUE)) { read_in = read_casualties( year = year, data_dir = data_dir, diff --git a/tests/testthat/test-dl_stats19.R b/tests/testthat/test-dl_stats19.R index d8e7cac..6703102 100644 --- a/tests/testthat/test-dl_stats19.R +++ b/tests/testthat/test-dl_stats19.R @@ -13,6 +13,10 @@ test_that("dl_stats19 works for no data_dir", { skip_download() # remove tempdir unlink(tempdir(), recursive = TRUE) - expect_message(dl_stats19(year = "2022", type = "collision")) + y = "2022" + t = "collision" + expect_message(dl_stats19(year = y, type = t)) # tempdir created. + file = find_file_name(years = y, type = t) + expect_match(file, t) })