Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions R/covidcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ parse_signal <- function(signal, base_url) {
}

#' @export
print.covidcast_data_signal <- function(signal, ...) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you're preferring a more generic variable name?

Copy link
Contributor Author

@capnrefsmmat capnrefsmmat Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're required to use x, because that's how print() is defined in base R:

> print
function (x, ...) 
UseMethod("print")

See https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Generic-functions-and-methods

This is checked by R CMD check, which issues warnings when the argument names don't match.

print(signal$name)
print(signal$key)
print(signal$short_description)
print.covidcast_data_signal <- function(x, ...) {
print(x$name)
print(x$key)
print(x$short_description)
}

parse_source <- function(source, base_url) {
Expand Down Expand Up @@ -79,11 +79,11 @@ as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
}

#' @export
print.covidcast_data_source <- function(source, ...) {
print(source$name, ...)
print(source$source, ...)
print(source$description, ...)
signals <- as.data.frame(source$signals)
print.covidcast_data_source <- function(x, ...) {
print(x$name, ...)
print(x$source, ...)
print(x$description, ...)
signals <- as.data.frame(x$signals)
print(signals[, c("signal", "name", "short_description")], ...)
}

Expand Down Expand Up @@ -155,16 +155,16 @@ as.data.frame.covidcast_data_source_list <- function(sources, ...) {
}), ...)
}

print.covidcast_epidata <- function(epidata, ...) {
print.covidcast_epidata <- function(x, ...) {
print("COVIDcast Epidata Fetcher")
print("Sources:")
sources <- as.data.frame(epidata$sources)
sources <- as.data.frame(x$sources)
print(sources[1:5, c("source", "name")], ...)
if (nrow(sources) > 5) {
print(paste0((nrow(sources) - 5), " more..."))
}
print("Signals")
signals <- as.data.frame(epidata$signals)
signals <- as.data.frame(x$signals)
print(signals[1:5, c("source", "signal", "name")], ...)
if (nrow(signals) > 5) {
print(paste0((nrow(signals) - 5), " more..."))
Expand Down
6 changes: 3 additions & 3 deletions R/epidatacall.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ request_arguments <- function(epidata_call, format_type, fields = NULL) {
}

#' @export
print.epidata_call <- function(epidata_call) {
stopifnot(inherits(epidata_call, "epidata_call"))
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",
"*" = paste0("Request URL: ", request_url(epidata_call))
"*" = paste0("Request URL: ", request_url(x))
))
}

Expand Down