Skip to content

Commit 83e7ce3

Browse files
committed
combine epiweek and date into time_type and time_value for pvt_twitter
1 parent d1db445 commit 83e7ce3

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

R/endpoints.R

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,15 +2094,17 @@ pvt_sensors <- function(
20942094
#' pvt_twitter(
20952095
#' auth = Sys.getenv("SECRET_API_AUTH_TWITTER"),
20962096
#' locations = "CA",
2097-
#' epiweeks = epirange(201501, 202001)
2097+
#' time_type = "week",
2098+
#' time_values = epirange(201501, 202001)
20982099
#' )
20992100
#' }
21002101
#' @param auth string. Restricted access key (not the same as API key).
21012102
#' @param locations character. Locations to fetch.
21022103
#' @param ... not used for values, forces later arguments to bind by name
2103-
#' @param dates [`timeset`]. Dates to fetch. Mutually exclusive with `epiweeks`.
2104-
#' @param epiweeks [`timeset`]. Epiweeks to fetch. Mutually exclusive with
2105-
#' `dates`.
2104+
#' @param time_type string. The temporal resolution of the data (either "day" or
2105+
#' "week", depending on signal).
2106+
#' @param time_values [`timeset`]. Dates or epiweeks to fetch. Defaults to all
2107+
#' ("*") dates.
21062108
#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`.
21072109
#' @return [`tibble::tibble`]
21082110
#' @keywords endpoint
@@ -2111,21 +2113,31 @@ pvt_twitter <- function(
21112113
auth,
21122114
locations,
21132115
...,
2114-
dates = NULL,
2115-
epiweeks = NULL,
2116+
time_type = c("day", "week"),
2117+
time_values = "*",
21162118
fetch_args = fetch_args_list()) {
21172119
rlang::check_dots_empty()
21182120

2121+
time_type <- match.arg(time_type)
2122+
if (time_type == "day") {
2123+
dates <- time_values
2124+
epiweeks <- NULL
2125+
dates <- get_wildcard_equivalent_dates(dates, "day")
2126+
} else {
2127+
dates <- NULL
2128+
epiweeks <- time_values
2129+
epiweeks <- get_wildcard_equivalent_dates(epiweeks, "week")
2130+
}
2131+
21192132
assert_character_param("auth", auth, len = 1)
21202133
assert_character_param("locations", locations)
2134+
assert_character_param("time_type", time_type, len = 1)
2135+
assert_timeset_param("time_values", time_values)
21212136
assert_timeset_param("dates", dates, required = FALSE)
21222137
assert_timeset_param("epiweeks", epiweeks, required = FALSE)
21232138
dates <- parse_timeset_input(dates)
21242139
epiweeks <- parse_timeset_input(epiweeks)
21252140

2126-
if (!xor(is.null(dates), is.null(epiweeks))) {
2127-
stop("exactly one of `dates` and `epiweeks` is required")
2128-
}
21292141
time_field <- if (!is.null(dates)) {
21302142
create_epidata_field_info("date", "date")
21312143
} else {
@@ -2164,9 +2176,9 @@ pvt_twitter <- function(
21642176
#' @examples
21652177
#' \dontrun{
21662178
#' pub_wiki(
2167-
#' articles = "avian_influenza",
2168-
#' time_type = "week",
2169-
#' time_values = epirange(201501, 201601)
2179+
#' articles = "avian_influenza",
2180+
#' time_type = "week",
2181+
#' time_values = epirange(201501, 201601)
21702182
#' )
21712183
#' }
21722184
#' @param articles character. Articles to fetch.

man/pub_wiki.Rd

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

man/pvt_twitter.Rd

Lines changed: 8 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ test_that("basic_epidata_call", {
137137
expect_no_error(pvt_twitter(
138138
auth = "yourkey",
139139
locations = "CA",
140-
epiweeks = epirange(201501, 202001),
140+
time_type = "week",
141+
time_values = epirange(201501, 202001),
141142
fetch_args = fetch_args_list(dry_run = TRUE)
142143
) %>% request_url())
143144
expect_no_error(pub_wiki(
@@ -414,7 +415,8 @@ test_that("endpoints fail when given args via dots", {
414415
pvt_twitter(
415416
auth = "yourkey",
416417
locations = "CA",
417-
date_range = epirange(201501, 202001)
418+
time_type = "week",
419+
time_range = epirange(201501, 202001)
418420
),
419421
regexp = dots_error
420422
)

vignettes/signal-discovery.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ API docs: <https://cmu-delphi.github.io/delphi-epidata/api/twitter.html>
378378
pvt_twitter(
379379
auth = Sys.getenv("SECRET_API_AUTH_TWITTER"),
380380
locations = "nat",
381-
epiweeks = epirange(200301, 202105)
381+
time_type = "week",
382+
time_values = epirange(200301, 202105)
382383
)
383384
```
384385

0 commit comments

Comments
 (0)