Skip to content

Commit d1db445

Browse files
committed
combine epiweek and date into time_type and time_value for pub_wiki
This makes the pub_wiki interfaces better match that of the other endpoints. Also build in time_values default of "*".
1 parent d9def9f commit d1db445

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

R/endpoints.R

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,13 +2163,18 @@ pvt_twitter <- function(
21632163
#'
21642164
#' @examples
21652165
#' \dontrun{
2166-
#' pub_wiki(articles = "avian_influenza", epiweeks = epirange(201501, 201601))
2166+
#' pub_wiki(
2167+
#' articles = "avian_influenza",
2168+
#' time_type = "week",
2169+
#' time_values = epirange(201501, 201601)
2170+
#' )
21672171
#' }
21682172
#' @param articles character. Articles to fetch.
21692173
#' @param ... not used for values, forces later arguments to bind by name
2170-
#' @param dates [`timeset`]. Dates to fetch. Mutually exclusive with `epiweeks`.
2171-
#' @param epiweeks [`timeset`]. Epiweeks to fetch. Mutually exclusive with
2172-
#' `dates`.
2174+
#' @param time_type string. The temporal resolution of the data (either "day" or
2175+
#' "week", depending on signal).
2176+
#' @param time_values [`timeset`]. Dates or epiweeks to fetch. Defaults to all
2177+
#' ("*") dates.
21732178
#' @param language string. Language to fetch.
21742179
#' @param hours integer. Optionally, the hours to fetch.
21752180
#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`.
@@ -2179,24 +2184,34 @@ pvt_twitter <- function(
21792184
pub_wiki <- function(
21802185
articles,
21812186
...,
2182-
dates = NULL,
2183-
epiweeks = NULL,
2187+
time_type = c("day", "week"),
2188+
time_values = "*",
21842189
hours = NULL,
21852190
language = "en",
21862191
fetch_args = fetch_args_list()) {
21872192
rlang::check_dots_empty()
21882193

2194+
time_type <- match.arg(time_type)
2195+
if (time_type == "day") {
2196+
dates <- time_values
2197+
epiweeks <- NULL
2198+
dates <- get_wildcard_equivalent_dates(dates, "day")
2199+
} else {
2200+
dates <- NULL
2201+
epiweeks <- time_values
2202+
epiweeks <- get_wildcard_equivalent_dates(epiweeks, "week")
2203+
}
2204+
21892205
assert_character_param("articles", articles)
2206+
assert_character_param("time_type", time_type, len = 1)
2207+
assert_timeset_param("time_values", time_values)
21902208
assert_timeset_param("dates", dates, required = FALSE)
21912209
assert_timeset_param("epiweeks", epiweeks, required = FALSE)
21922210
assert_integerish_param("hours", hours, required = FALSE)
21932211
assert_character_param("language", language, len = 1, required = FALSE)
21942212
dates <- parse_timeset_input(dates)
21952213
epiweeks <- parse_timeset_input(epiweeks)
21962214

2197-
if (!xor(is.null(dates), is.null(epiweeks))) {
2198-
stop("exactly one of `dates` and `epiweeks` is required")
2199-
}
22002215
time_field <- if (!is.null(dates)) {
22012216
create_epidata_field_info("date", "date")
22022217
} else {

man/pub_wiki.Rd

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-endpoints.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ test_that("basic_epidata_call", {
142142
) %>% request_url())
143143
expect_no_error(pub_wiki(
144144
articles = "avian_influenza",
145-
epiweeks = epirange(201501, 202001),
145+
time_type = "week",
146+
time_values = epirange(201501, 202001),
146147
fetch_args = fetch_args_list(dry_run = TRUE)
147148
) %>% request_url())
148149
})
@@ -420,6 +421,7 @@ test_that("endpoints fail when given args via dots", {
420421
expect_error(
421422
pub_wiki(
422423
articles = "avian_influenza",
424+
time_type = "week",
423425
date_range = epirange(201501, 202001)
424426
),
425427
regexp = dots_error

vignettes/signal-discovery.Rmd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ pub_paho_dengue(regions = "ca", epiweeks = epirange(200201, 202319))
282282
API docs: <https://cmu-delphi.github.io/delphi-epidata/api/wiki.html>
283283

284284
```{r, eval = FALSE}
285-
pub_wiki(language = "en", articles = "influenza", epiweeks = epirange(202001, 202319))
285+
pub_wiki(
286+
language = "en",
287+
articles = "influenza",
288+
time_type = "week",
289+
time_values = epirange(202001, 202319)
290+
)
286291
```
287292

288293
### Private methods

0 commit comments

Comments
 (0)