Skip to content

Commit 9675aec

Browse files
committed
wip: epi_archive print #341
1 parent fc528de commit 9675aec

6 files changed

+107
-93
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ S3method(group_modify,epi_df)
2222
S3method(groups,grouped_epi_archive)
2323
S3method(next_after,Date)
2424
S3method(next_after,integer)
25+
S3method(print,epi_archive)
2526
S3method(print,epi_df)
2627
S3method(select,epi_df)
2728
S3method(summary,epi_df)

R/archive.R

-63
Original file line numberDiff line numberDiff line change
@@ -439,69 +439,6 @@ epi_archive <-
439439
self$clobberable_versions_start <- clobberable_versions_start
440440
self$versions_end <- versions_end
441441
},
442-
#' Print information about an archive
443-
#' @param class Boolean; whether to print the class label header
444-
#' @param methods Boolean; whether to print all available methods of
445-
#' the archive
446-
print = function(class = TRUE, methods = TRUE) {
447-
if (class) cat("An `epi_archive` object, with metadata:\n")
448-
cat(sprintf("* %-9s = %s\n", "geo_type", self$geo_type))
449-
cat(sprintf("* %-9s = %s\n", "time_type", self$time_type))
450-
if (!is.null(self$additional_metadata)) {
451-
sapply(self$additional_metadata, function(m) {
452-
cat(sprintf("* %-9s = %s\n", names(m), m))
453-
})
454-
}
455-
cat("----------\n")
456-
if (length(self$DT$time_value) == 0 || all(is.na(self$DT$time_value))) {
457-
min_time <- max_time <- NA
458-
} else {
459-
min_time <- Min(self$DT$time_value)
460-
max_time <- Max(self$DT$time_value)
461-
}
462-
cat(sprintf("* %-14s = %s\n", "min time value", min_time))
463-
cat(sprintf("* %-14s = %s\n", "max time value", max_time))
464-
cat(sprintf(
465-
"* %-14s = %s\n", "first version with update",
466-
min(self$DT$version)
467-
))
468-
cat(sprintf(
469-
"* %-14s = %s\n", "last version with update",
470-
max(self$DT$version)
471-
))
472-
if (is.na(self$clobberable_versions_start)) {
473-
cat("* No clobberable versions\n")
474-
} else {
475-
cat(sprintf(
476-
"* %-14s = %s\n", "clobberable versions start",
477-
self$clobberable_versions_start
478-
))
479-
}
480-
cat(sprintf(
481-
"* %-14s = %s\n", "versions end",
482-
self$versions_end
483-
))
484-
cat("----------\n")
485-
cat(sprintf(
486-
"Data archive (stored in DT field): %i x %i\n",
487-
nrow(self$DT), ncol(self$DT)
488-
))
489-
cat(sprintf("Columns in DT: %s\n", paste(ifelse(length(
490-
colnames(self$DT)
491-
) <= 4, paste(colnames(self$DT), collapse = ", "),
492-
paste(
493-
paste(colnames(self$DT)[1:4], collapse = ", "), "and",
494-
length(colnames(self$DT)[5:length(colnames(self$DT))]), "more columns"
495-
)
496-
))))
497-
if (methods) {
498-
cat("----------\n")
499-
writeLines(wrap_varnames(
500-
initial = "Public R6 methods: ",
501-
names(epi_archive$public_methods)
502-
))
503-
}
504-
},
505442
#####
506443
#' @description Generates a snapshot in `epi_df` format as of a given version.
507444
#' See the documentation for the wrapper function [`epix_as_of()`] for

R/methods-epi_archive.R

+76
Original file line numberDiff line numberDiff line change
@@ -1000,3 +1000,79 @@ epix_truncate_versions_after.epi_archive <- function(x, max_version) {
10001000
return((x$clone()$truncate_versions_after(max_version)))
10011001
# ^ second set of parens drops invisibility
10021002
}
1003+
1004+
#' Print and summary functions for an `epi_archive` object.
1005+
#'
1006+
#' @param x The `epi_archive` object.
1007+
#' @param class Boolean; whether to print the class label header
1008+
#' @param methods Boolean; whether to print all available methods of
1009+
#' the archive
1010+
#' @param ... Additional arguments passed to methods.
1011+
#'
1012+
#' @method print epi_archive
1013+
#' @export
1014+
print.epi_archive <- function(x, class = TRUE, methods = TRUE, ...) {
1015+
# --- Copied from R6 ---
1016+
if (class) cat("An `epi_archive` object, with metadata:\n")
1017+
cat(sprintf("* %-9s = %s\n", "geo_type", x$geo_type))
1018+
cat(sprintf("* %-9s = %s\n", "time_type", x$time_type))
1019+
if (!is.null(x$additional_metadata)) {
1020+
sapply(x$additional_metadata, function(m) {
1021+
cat(sprintf("* %-9s = %s\n", names(m), m))
1022+
})
1023+
}
1024+
cat("----------\n")
1025+
if (length(x$DT$time_value) == 0 || all(is.na(x$DT$time_value))) {
1026+
min_time <- max_time <- NA
1027+
} else {
1028+
min_time <- Min(x$DT$time_value)
1029+
max_time <- Max(x$DT$time_value)
1030+
}
1031+
cat(sprintf("* %-14s = %s\n", "min time value", min_time))
1032+
cat(sprintf("* %-14s = %s\n", "max time value", max_time))
1033+
cat(sprintf(
1034+
"* %-14s = %s\n", "first version with update",
1035+
min(x$DT$version)
1036+
))
1037+
cat(sprintf(
1038+
"* %-14s = %s\n", "last version with update",
1039+
max(x$DT$version)
1040+
))
1041+
if (is.na(x$clobberable_versions_start)) {
1042+
cat("* No clobberable versions\n")
1043+
} else {
1044+
cat(sprintf(
1045+
"* %-14s = %s\n", "clobberable versions start",
1046+
x$clobberable_versions_start
1047+
))
1048+
}
1049+
cat(sprintf(
1050+
"* %-14s = %s\n", "versions end",
1051+
x$versions_end
1052+
))
1053+
cat("----------\n")
1054+
cat(sprintf(
1055+
"Data archive (stored in DT field): %i x %i\n",
1056+
nrow(x$DT), ncol(x$DT)
1057+
))
1058+
cat(sprintf("Columns in DT: %s\n", paste(ifelse(length(
1059+
colnames(x$DT)
1060+
) <= 4, paste(colnames(x$DT), collapse = ", "),
1061+
paste(
1062+
paste(colnames(x$DT)[1:4], collapse = ", "), "and",
1063+
length(colnames(x$DT)[5:length(colnames(x$DT))]), "more columns"
1064+
)
1065+
))))
1066+
if (methods) {
1067+
cat("----------\n")
1068+
writeLines(wrap_varnames(
1069+
initial = "Public R6 methods: ",
1070+
names(epi_archive$public_methods)
1071+
))
1072+
}
1073+
1074+
# Error in NextMethod() : generic function not specified
1075+
# NextMethod()
1076+
1077+
x$DT %>% tibble %>% print
1078+
}

man/epi_archive.Rd

-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/jhu_csse_daily_subset.Rd

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.epi_archive.Rd

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)