diff --git a/NAMESPACE b/NAMESPACE index 9b5b245c..d9630348 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,11 +2,14 @@ S3method(as_tibble,covidcast_data_signal_list) S3method(as_tibble,covidcast_data_source_list) +S3method(print,EpiRange) +S3method(print,EpidataFieldInfo) S3method(print,covidcast_data_signal) S3method(print,covidcast_data_signal_list) S3method(print,covidcast_data_source) S3method(print,covidcast_epidata) S3method(print,epidata_call) +S3method(print,fetch_args) export(avail_endpoints) export(cache_info) export(clear_cache) diff --git a/R/epidatacall.R b/R/epidatacall.R index 625a377e..cde20c9b 100644 --- a/R/epidatacall.R +++ b/R/epidatacall.R @@ -121,7 +121,6 @@ request_arguments <- function(epidata_call, format_type, fields = NULL) { #' @export print.epidata_call <- function(x, ...) { - stopifnot(inherits(x, "epidata_call")) cli::cli_h1(" object:") cli::cli_bullets(c( "*" = "Pipe this object into `fetch()` to actually fetch the data", @@ -198,6 +197,13 @@ fetch_args_list <- function( ) } +#' @export +print.fetch_args <- function(x, ...) { + cli::cli_h1(" object:") + # Print all non-class fields. + cli::cli_dl(x[attr(x, "names")]) +} + #' Fetches the data #' #' @details diff --git a/R/model.R b/R/model.R index 8ba7a2b6..a14f8960 100644 --- a/R/model.R +++ b/R/model.R @@ -61,6 +61,27 @@ epirange <- function(from, to) { structure(list(from = from, to = to), class = "EpiRange") } +#' @export +print.EpiRange <- function(x, ...) { + if (nchar(x$from) == 8) { + date_type <- "Days" # nolint: object_usage_linter + x$from <- as.Date(as.character(x$from), "%Y%m%d") + x$to <- as.Date(as.character(x$to), "%Y%m%d") + } else if (nchar(x$from) == 6) { + date_type <- "Epiweeks" # nolint: object_usage_linter + x$from <- paste0( + substr(x$from, 1, 4), "w", substr(x$from, 5, 6) + ) + x$to <- paste0( + substr(x$to, 1, 4), "w", substr(x$to, 5, 6) + ) + } + + cli::cli_h1(" object:") + cli::cli_bullets( + "{date_type} from {x$from} to {x$to}" + ) +} #' Timeset formats for specifying dates #' @@ -86,7 +107,6 @@ epirange <- function(from, to) { #' @name timeset NULL - create_epidata_field_info <- function(name, type, description = "", @@ -117,6 +137,13 @@ create_epidata_field_info <- function(name, ) } +#' @export +print.EpidataFieldInfo <- function(x, ...) { + cli::cli_h1(" object:") + # Print all non-class fields. + cli::cli_dl(x[attr(x, "names")]) +} + parse_value <- function(info, value, disable_date_parsing = FALSE) { stopifnot(inherits(info, "EpidataFieldInfo"))