Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion R/epidatacall.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<epidata_call> object:")
cli::cli_bullets(c(
"*" = "Pipe this object into `fetch()` to actually fetch the data",
Expand Down Expand Up @@ -198,6 +197,13 @@ fetch_args_list <- function(
)
}

#' @export
print.fetch_args <- function(x, ...) {
cli::cli_h1("<fetch_args> object:")
# Print all non-class fields.
cli::cli_dl(x[attr(x, "names")])
}

#' Fetches the data
#'
#' @details
Expand Down
29 changes: 28 additions & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<EpiRange> object:")
cli::cli_bullets(
"{date_type} from {x$from} to {x$to}"
)
}

#' Timeset formats for specifying dates
#'
Expand All @@ -86,7 +107,6 @@ epirange <- function(from, to) {
#' @name timeset
NULL


create_epidata_field_info <- function(name,
type,
description = "",
Expand Down Expand Up @@ -117,6 +137,13 @@ create_epidata_field_info <- function(name,
)
}

#' @export
print.EpidataFieldInfo <- function(x, ...) {
cli::cli_h1("<EpidataFieldInfo> 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"))

Expand Down