From 66722311e058a6664fea4d90eda40104d4687af6 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Mon, 29 Jan 2024 15:59:27 -0800 Subject: [PATCH 1/4] refactor: unclutter epi_archive print, add DT preview --- R/archive.R | 50 +++++++++++++----------------------- man/jhu_csse_daily_subset.Rd | 18 ++++++------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/R/archive.R b/R/archive.R index faaf048b..afd74a64 100644 --- a/R/archive.R +++ b/R/archive.R @@ -445,13 +445,10 @@ epi_archive <- #' the archive 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(sprintf("* %-14s = %s\n", "non-standard DT keys", paste( + setdiff(key(self$DT), c("geo_value", "time_value", "version")), + collapse = ", " + ))) cat("----------\n") if (length(self$DT$time_value) == 0 || all(is.na(self$DT$time_value))) { min_time <- max_time <- NA @@ -459,19 +456,16 @@ epi_archive <- 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", "min/max time values", paste( + c(min_time, max_time), + collapse = " / " + ))) 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 { + "* %-14s = %s\n", "first/last version with update", paste( + c(min(self$DT$version), max(self$DT$version)), + collapse = " / " + ))) + if (!is.na(self$clobberable_versions_start)) { cat(sprintf( "* %-14s = %s\n", "clobberable versions start", self$clobberable_versions_start @@ -481,19 +475,6 @@ epi_archive <- "* %-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" - ) - )))) if (methods) { cat("----------\n") writeLines(wrap_varnames( @@ -501,6 +482,11 @@ epi_archive <- names(epi_archive$public_methods) )) } + cat("----------\n") + cat(sprintf( + "A preview of the table: %s rows x %s columns\n", + nrow(self$DT), ncol(self$DT))) + 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{ From c3e68d3d68265c295425628319735ed9eacdb1a1 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Mon, 29 Jan 2024 16:04:37 -0800 Subject: [PATCH 2/4] doc: add tentative news blurb, version number --- DESCRIPTION | 8 ++++---- NEWS.md | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) 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/NEWS.md b/NEWS.md index 3d02b981..27bf793d 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. Now an S3 method and shows a snippet of + the underlying `DT` (#341). ## Breaking changes From 1ca789bb61a2935b422aa387712cc3a79b69dd75 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 31 Jan 2024 11:24:05 -0800 Subject: [PATCH 3/4] doc: update NEWS --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 27bf793d..e4a404e2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,8 +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. Now an S3 method and shows a snippet of - the underlying `DT` (#341). +* Improved `epi_archive` print method. Compactified metadata and shows a snippet + of the underlying `DT` (#341). ## Breaking changes From 13873f2908ba4774ab02e1a82a87afd4549ed622 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Wed, 31 Jan 2024 13:07:41 -0800 Subject: [PATCH 4/4] refactor: use cli for print --- NAMESPACE | 1 + R/archive.R | 60 ++++++++++++++++------------------------------------- 2 files changed, 19 insertions(+), 42 deletions(-) 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/R/archive.R b/R/archive.R index afd74a64..08540955 100644 --- a/R/archive.R +++ b/R/archive.R @@ -443,49 +443,25 @@ 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("* %-14s = %s\n", "non-standard DT keys", paste( - setdiff(key(self$DT), c("geo_value", "time_value", "version")), - collapse = ", " - ))) - 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/max time values", paste( - c(min_time, max_time), - collapse = " / " - ))) - cat(sprintf( - "* %-14s = %s\n", "first/last version with update", paste( - c(min(self$DT$version), max(self$DT$version)), - collapse = " / " - ))) - if (!is.na(self$clobberable_versions_start)) { - cat(sprintf( - "* %-14s = %s\n", "clobberable versions start", - self$clobberable_versions_start - )) - } - cat(sprintf( - "* %-14s = %s\n", "versions end", - self$versions_end - )) - if (methods) { - cat("----------\n") - writeLines(wrap_varnames( - initial = "Public R6 methods: ", - names(epi_archive$public_methods) - )) - } - cat("----------\n") - cat(sprintf( - "A preview of the table: %s rows x %s columns\n", - nrow(self$DT), ncol(self$DT))) + 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):" + ) + ) + return(invisible(self$DT %>% print)) }, #####