From 562b75342fa31f186106a6aa17c5aef3df897f97 Mon Sep 17 00:00:00 2001 From: Elin Waring Date: Tue, 26 Apr 2022 08:08:36 -0400 Subject: [PATCH] Create print.one_skim_df, document reassign_skim_attrs and modify reconcile_skimrs in response to changes in 4.2 and R CMD CHK issues. --- NAMESPACE | 1 + R/reshape.R | 2 +- R/skim_obj.R | 7 +++++-- R/skim_print.R | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 78b94d8a..2c24eefe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ S3method(knit_print,skim_df) S3method(knit_print,skim_list) S3method(knit_print,summary_skim_df) S3method(mutate,skim_df) +S3method(print,one_skim_df) S3method(print,skim_df) S3method(print,skim_list) S3method(print,summary_skim_df) diff --git a/R/reshape.R b/R/reshape.R index 8414c773..0ed828a7 100644 --- a/R/reshape.R +++ b/R/reshape.R @@ -79,7 +79,7 @@ reconcile_skimmers <- function(data, groups, base) { )) matched_cols <- dplyr::intersect(all_columns, with_base_columns) extra_cols <- dplyr::setdiff(all_columns, with_base_columns) - if (length(extra_cols) > 0) { + if (length(extra_cols) > 0 && "skim_type" %in% names(data)) { grouped <- dplyr::group_by(data, .data$skim_type) complete_by_type <- dplyr::summarize_at( grouped, diff --git a/R/skim_obj.R b/R/skim_obj.R index 9ca8c125..e5170cda 100644 --- a/R/skim_obj.R +++ b/R/skim_obj.R @@ -257,9 +257,12 @@ strip_skim_attrs <- function(object) { attributes(object) <- stripped object } - +#' @param object a skim object +#' @param skim_df name of new skim object +#' @param ... additional options +#' #' Pass attributes from a `skimr` object to a new object. -#' @noRd +#' @keywords internal reassign_skim_attrs <- function(object, skim_df, ...) { defaults <- list( class = c("skim_df", "tbl_df", "tbl", "data.frame"), diff --git a/R/skim_print.R b/R/skim_print.R index 8cedafee..4ae69e98 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -61,6 +61,27 @@ print.skim_df <- function(x, } } +#' @export +print.one_skim_df <- function(x, + include_summary = TRUE, + n = Inf, + width = Inf, + summary_rule_width = getOption( + "skimr_summary_rule_width", + default = 40 + ), + ...) { + if (is_skim_df(x) && nrow(x) > 0) { + if (include_summary) { + print(summary(x), .summary_rule_width = summary_rule_width, ...) + } + + print(x, width = width, n = n, ...) + } else { + NextMethod("print") + } +} + # Methods for correctly formatting a a `one_skim_df`. We leverage the # customiztion options in `pillar` for this. It divides the results into: a