Skip to content

Commit

Permalink
combine epiweek and date into time_type and time_value for pvt_twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Jan 5, 2024
1 parent 71de7d5 commit 1abba96
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
30 changes: 21 additions & 9 deletions R/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -2103,15 +2103,17 @@ pvt_sensors <- function(
#' pvt_twitter(
#' auth = Sys.getenv("SECRET_API_AUTH_TWITTER"),
#' locations = "CA",
#' epiweeks = epirange(201501, 202001)
#' time_type = "week",
#' time_values = epirange(201501, 202001)
#' )
#' }
#' @param auth string. Restricted access key (not the same as API key).
#' @param locations character. Locations to fetch.
#' @param ... not used for values, forces later arguments to bind by name
#' @param dates [`timeset`]. Dates to fetch. Mutually exclusive with `epiweeks`.
#' @param epiweeks [`timeset`]. Epiweeks to fetch. Mutually exclusive with
#' `dates`.
#' @param time_type string. The temporal resolution of the data (either "day" or
#' "week", depending on signal).
#' @param time_values [`timeset`]. Dates or epiweeks to fetch. Defaults to all
#' ("*") dates.
#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`.
#' @return [`tibble::tibble`]
#' @keywords endpoint
Expand All @@ -2120,21 +2122,31 @@ pvt_twitter <- function(
auth,
locations,
...,
dates = NULL,
epiweeks = NULL,
time_type = c("day", "week"),
time_values = "*",
fetch_args = fetch_args_list()) {
rlang::check_dots_empty()

time_type <- match.arg(time_type)
if (time_type == "day") {
dates <- time_value
epiweeks <- NULL
dates <- get_wildcard_equivalent_dates(dates, "day")
} else {
dates <- NULL
epiweeks <- time_value
epiweeks <- get_wildcard_equivalent_dates(epiweeks, "week")
}

assert_character_param("auth", auth, len = 1)
assert_character_param("locations", locations)
assert_character_param("time_type", time_type, len = 1)
assert_timeset_param("time_values", time_values)
assert_timeset_param("dates", dates, required = FALSE)
assert_timeset_param("epiweeks", epiweeks, required = FALSE)
dates <- parse_timeset_input(dates)
epiweeks <- parse_timeset_input(epiweeks)

if (!xor(is.null(dates), is.null(epiweeks))) {
stop("exactly one of `dates` and `epiweeks` is required")
}
time_field <- if (!is.null(dates)) {
create_epidata_field_info("date", "date")
} else {
Expand Down
14 changes: 8 additions & 6 deletions man/pvt_twitter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/testthat/test-endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ test_that("basic_epidata_call", {
expect_no_error(pvt_twitter(
auth = "yourkey",
locations = "CA",
epiweeks = epirange(201501, 202001),
time_type = "week",
time_values = epirange(201501, 202001),
fetch_args = fetch_args_list(dry_run = TRUE)
) %>% request_url())
expect_no_error(pub_wiki(
Expand Down Expand Up @@ -237,7 +238,8 @@ test_that("endpoints fail when given args via dots", {
pvt_twitter(
auth = "yourkey",
locations = "CA",
date_range = epirange(201501, 202001)
time_type = "week",
time_range = epirange(201501, 202001)
),
regexp = dots_error
)
Expand Down
3 changes: 2 additions & 1 deletion vignettes/signal-discovery.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ API docs: <https://cmu-delphi.github.io/delphi-epidata/api/twitter.html>
pvt_twitter(
auth = Sys.getenv("SECRET_API_AUTH_TWITTER"),
locations = "nat",
epiweeks = epirange(200301, 202105)
time_type = "week",
time_values = epirange(200301, 202105)
)
```

Expand Down

0 comments on commit 1abba96

Please sign in to comment.