diff --git a/DESCRIPTION b/DESCRIPTION index 15b7757f..46bf204d 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: epiprocess Title: Tools for basic signal processing in epidemiology -Version: 0.7.2 +Version: 0.7.3 Authors@R: c( person("Jacob", "Bien", role = "ctb"), person("Logan", "Brooks", role = "aut"), @@ -56,7 +56,7 @@ Suggests: testthat (>= 3.1.5), waldo (>= 0.3.1), withr -VignetteBuilder: +VignetteBuilder: knitr Remotes: cmu-delphi/epidatr, @@ -67,10 +67,10 @@ Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -Depends: +Depends: R (>= 2.10) URL: https://cmu-delphi.github.io/epiprocess/ -Collate: +Collate: 'archive.R' 'correlation.R' 'data.R' diff --git a/NAMESPACE b/NAMESPACE index c59004c8..9ae3464f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ export(slice) export(ungroup) export(unnest) importFrom(R6,R6Class) +importFrom(cli,cli_inform) importFrom(data.table,":=") importFrom(data.table,address) importFrom(data.table,as.data.table) diff --git a/NEWS.md b/NEWS.md index 3d02b981..e4a404e2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,8 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.x.y will indicat * changed approach to versioning, see DEVELOPMENT.md for details * `select` on grouped `epi_df`s now only drops `epi_df`ness if it makes sense; PR #390 * Minor documentation updates; PR #393 +* Improved `epi_archive` print method. Compactified metadata and shows a snippet + of the underlying `DT` (#341). ## Breaking changes diff --git a/R/archive.R b/R/archive.R index faaf048b..08540955 100644 --- a/R/archive.R +++ b/R/archive.R @@ -443,64 +443,26 @@ epi_archive <- #' @param class Boolean; whether to print the class label header #' @param methods Boolean; whether to print all available methods of #' the archive + #' @importFrom cli cli_inform print = function(class = TRUE, methods = TRUE) { - if (class) cat("An `epi_archive` object, with metadata:\n") - cat(sprintf("* %-9s = %s\n", "geo_type", self$geo_type)) - cat(sprintf("* %-9s = %s\n", "time_type", self$time_type)) - if (!is.null(self$additional_metadata)) { - sapply(self$additional_metadata, function(m) { - cat(sprintf("* %-9s = %s\n", names(m), m)) - }) - } - cat("----------\n") - if (length(self$DT$time_value) == 0 || all(is.na(self$DT$time_value))) { - min_time <- max_time <- NA - } else { - min_time <- Min(self$DT$time_value) - max_time <- Max(self$DT$time_value) - } - cat(sprintf("* %-14s = %s\n", "min time value", min_time)) - cat(sprintf("* %-14s = %s\n", "max time value", max_time)) - cat(sprintf( - "* %-14s = %s\n", "first version with update", - min(self$DT$version) - )) - cat(sprintf( - "* %-14s = %s\n", "last version with update", - max(self$DT$version) - )) - if (is.na(self$clobberable_versions_start)) { - cat("* No clobberable versions\n") - } else { - cat(sprintf( - "* %-14s = %s\n", "clobberable versions start", - self$clobberable_versions_start - )) - } - cat(sprintf( - "* %-14s = %s\n", "versions end", - self$versions_end - )) - cat("----------\n") - cat(sprintf( - "Data archive (stored in DT field): %i x %i\n", - nrow(self$DT), ncol(self$DT) - )) - cat(sprintf("Columns in DT: %s\n", paste(ifelse(length( - colnames(self$DT) - ) <= 4, paste(colnames(self$DT), collapse = ", "), - paste( - paste(colnames(self$DT)[1:4], collapse = ", "), "and", - length(colnames(self$DT)[5:length(colnames(self$DT))]), "more columns" + cli_inform( + c( + ">" = if (class) {"An `epi_archive` object, with metadata:"}, + "i" = if (length(setdiff(key(self$DT), c('geo_value', 'time_value', 'version'))) > 0) { + "Non-standard DT keys: {setdiff(key(self$DT), c('geo_value', 'time_value', 'version'))}" + }, + "i" = "Min/max time values: {min(self$DT$time_value)} / {max(self$DT$time_value)}", + "i" = "First/last version with update: {min(self$DT$version)} / {max(self$DT$version)}", + "i" = if (!is.na(self$clobberable_versions_start)) { + "Clobberable versions start: {self$clobberable_versions_start}" + }, + "i" = "Versions end: {self$versions_end}", + "i" = if (methods) {"Public R6 methods: {names(epi_archive$public_methods)}"}, + "i" = "A preview of the table ({nrow(self$DT)} rows x {ncol(self$DT)} columns):" + ) ) - )))) - if (methods) { - cat("----------\n") - writeLines(wrap_varnames( - initial = "Public R6 methods: ", - names(epi_archive$public_methods) - )) - } + + return(invisible(self$DT %>% print)) }, ##### #' @description Generates a snapshot in `epi_df` format as of a given version. diff --git a/man/jhu_csse_daily_subset.Rd b/man/jhu_csse_daily_subset.Rd index 626bf545..6d4913f0 100644 --- a/man/jhu_csse_daily_subset.Rd +++ b/man/jhu_csse_daily_subset.Rd @@ -30,15 +30,15 @@ in Engineering. Copyright Johns Hopkins University 2020. Modifications: \itemize{ -\item \href{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/jhu-csse.html}{From the COVIDcast Epidata API}: -These signals are taken directly from the JHU CSSE -\href{https://github.com/CSSEGISandData/COVID-19}{COVID-19 GitHub repository} -without changes. The 7-day average signals are computed by Delphi by -calculating moving averages of the preceding 7 days, so the signal for -June 7 is the average of the underlying data for June 1 through 7, -inclusive. -\item Furthermore, the data has been limited to a very small number of rows, -the signal names slightly altered, and formatted into a tibble. +\item \href{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/jhu-csse.html}{From +the COVIDcast Epidata API}: The case signal is taken directly from the JHU +CSSE \href{https://github.com/CSSEGISandData/COVID-19}{COVID-19 GitHub +repository}. The rate signals were computed by Delphi using Census +population data. The 7-day average signals were computed by Delphi by +calculating moving averages of the preceding 7 days, so the signal for June +7 is the average of the underlying data for June 1 through 7, inclusive. +\item Furthermore, the data has been limited to a very small number of rows, the +signal names slightly altered, and formatted into a tibble. } } \usage{