Skip to content

refactor: unclutter epi_archive print method #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 31, 2024
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
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -56,7 +56,7 @@ Suggests:
testthat (>= 3.1.5),
waldo (>= 0.3.1),
withr
VignetteBuilder:
VignetteBuilder:
knitr
Remotes:
cmu-delphi/epidatr,
Expand All @@ -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'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
74 changes: 18 additions & 56 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions man/jhu_csse_daily_subset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.