4444# ' @importFrom purrr map_chr map_lgl
4545create_epidata_call <- function (endpoint , params , meta = NULL ,
4646 only_supports_classic = FALSE ) {
47- stopifnot(is.character( endpoint ), length( endpoint ) = = 1 )
48- stopifnot(is.list( params ) )
49- stopifnot(is.null( meta ) || is.list( meta ) )
50- stopifnot(all(map_lgl( meta , ~ inherits( .x , " EpidataFieldInfo " ))) )
51- stopifnot(is.logical( only_supports_classic ), length( only_supports_classic ) == 1 )
47+ checkmate :: assert_character( endpoint , len = 1 )
48+ checkmate :: assert_list( params )
49+ checkmate :: assert_list( meta , null.ok = TRUE )
50+ checkmate :: assert_logical( only_supports_classic , len = 1 )
51+ checkmate :: assert_true(all(map_lgl( meta , ~ inherits( .x , " EpidataFieldInfo " ))) )
5252
5353 if (length(unique(meta )) != length(meta )) {
5454 cli :: cli_abort(
@@ -73,6 +73,10 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
7373 )
7474 }
7575
76+ # TODO: Check the categories in the future? We set up the categories
77+ # but we don't actually validate them yet?
78+ # use checkmate::assert_subset or something like that
79+
7680 if (is.null(meta )) {
7781 meta <- list ()
7882 }
@@ -155,7 +159,10 @@ print.epidata_call <- function(x, ...) {
155159# ' @param format_type the format to request from the API, one of classic, json,
156160# ' csv; this is only used by `fetch_debug`, and by default is `"json"`
157161# ' @param refresh_cache if `TRUE`, ignore the cache, fetch the data from the
158- # ' API, and update the cache, if it is enabled
162+ # ' API, and update the cache, if it is enabled
163+ # ' @param reference_week_day the day of the week to use as the reference day
164+ # ' when parsing epiweeks to dates (happens if `disable_date_parsing` is `FALSE`)
165+ # ' Defaults to 1 Sunday (the first day of the week).
159166# ' @return A `fetch_args` object containing all the specified options
160167# ' @export
161168# ' @aliases fetch_args
@@ -171,7 +178,8 @@ fetch_args_list <- function(
171178 dry_run = FALSE ,
172179 debug = FALSE ,
173180 format_type = c(" json" , " classic" , " csv" ),
174- refresh_cache = FALSE
181+ refresh_cache = FALSE ,
182+ reference_week_day = 1
175183) {
176184 rlang :: check_dots_empty()
177185
@@ -185,6 +193,7 @@ fetch_args_list <- function(
185193 assert_logical(debug , null.ok = FALSE , len = 1L , any.missing = FALSE )
186194 format_type <- match.arg(format_type )
187195 assert_logical(refresh_cache , null.ok = FALSE , len = 1L , any.missing = FALSE )
196+ assert_numeric(reference_week_day , null.ok = FALSE , len = 1L , any.missing = FALSE )
188197
189198 structure(
190199 list (
@@ -197,7 +206,8 @@ fetch_args_list <- function(
197206 dry_run = dry_run ,
198207 debug = debug ,
199208 format_type = format_type ,
200- refresh_cache = refresh_cache
209+ refresh_cache = refresh_cache ,
210+ reference_week_day = reference_week_day
201211 ),
202212 class = " fetch_args"
203213 )
@@ -270,7 +280,12 @@ fetch <- function(epidata_call, fetch_args = fetch_args_list()) {
270280 if (fetch_args $ return_empty && length(response_content ) == 0 ) {
271281 fetched <- tibble()
272282 } else {
273- fetched <- parse_data_frame(epidata_call , response_content , fetch_args $ disable_date_parsing ) %> % as_tibble()
283+ fetched <- parse_data_frame(
284+ epidata_call ,
285+ response_content ,
286+ fetch_args $ disable_date_parsing ,
287+ fetch_args $ reference_week_day
288+ ) %> % as_tibble()
274289 }
275290 })
276291
0 commit comments