diff --git a/R/endpoints.R b/R/endpoints.R index b2beb66a..8126e617 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -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 @@ -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 { diff --git a/man/pvt_twitter.Rd b/man/pvt_twitter.Rd index 30763a74..49cfdfc0 100644 --- a/man/pvt_twitter.Rd +++ b/man/pvt_twitter.Rd @@ -8,8 +8,8 @@ pvt_twitter( auth, locations, ..., - dates = NULL, - epiweeks = NULL, + time_type = c("day", "week"), + time_values = "*", fetch_args = fetch_args_list() ) } @@ -20,10 +20,11 @@ pvt_twitter( \item{...}{not used for values, forces later arguments to bind by name} -\item{dates}{\code{\link{timeset}}. Dates to fetch. Mutually exclusive with \code{epiweeks}.} +\item{time_type}{string. The temporal resolution of the data (either "day" or +"week", depending on signal).} -\item{epiweeks}{\code{\link{timeset}}. Epiweeks to fetch. Mutually exclusive with -\code{dates}.} +\item{time_values}{\code{\link{timeset}}. Dates or epiweeks to fetch. Defaults to all +("*") dates.} \item{fetch_args}{\code{\link{fetch_args}}. Additional arguments to pass to \code{fetch()}.} } @@ -41,7 +42,8 @@ Sourced from \href{http://www.healthtweets.org/}{Healthtweets} pvt_twitter( auth = Sys.getenv("SECRET_API_AUTH_TWITTER"), locations = "CA", - epiweeks = epirange(201501, 202001) + time_type = "week", + time_values = epirange(201501, 202001) ) } } diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index f2b8f67c..cecd41ab 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -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( @@ -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 ) diff --git a/vignettes/signal-discovery.Rmd b/vignettes/signal-discovery.Rmd index bbea800a..70a081ae 100644 --- a/vignettes/signal-discovery.Rmd +++ b/vignettes/signal-discovery.Rmd @@ -378,7 +378,8 @@ API docs: pvt_twitter( auth = Sys.getenv("SECRET_API_AUTH_TWITTER"), locations = "nat", - epiweeks = epirange(200301, 202105) + time_type = "week", + time_values = epirange(200301, 202105) ) ```