diff --git a/R/skim_print.R b/R/skim_print.R index 09d6ed35..5dbd4eaa 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -18,17 +18,25 @@ #' #' @inheritParams tibble:::print.tbl #' @param include_summary Whether a summary of the data frame should be printed +#' @param strip_metadata Whether tibble metadata should be removed. #' @name print NULL #' @describeIn print Print a skimmed data frame (`skim_df` from [skim()]). #' @export -print.skim_df <- function(x, include_summary = TRUE, n = Inf, width = Inf, - n_extra = NULL, ...) { +print.skim_df <- function(x, + include_summary = TRUE, + n = Inf, + width = Inf, + n_extra = NULL, + strip_metadata = TRUE, + ...) { if (is_skim_df(x)) { - if (include_summary) print(summary(x)) + if (include_summary) { + print(summary(x)) + } by_type <- partition(x) - purrr::imap(by_type, print, n, width, n_extra) + purrr::map(by_type, print, n, width, n_extra, strip_metadata, ...) invisible(NULL) } else { NextMethod("print") @@ -37,12 +45,20 @@ print.skim_df <- function(x, include_summary = TRUE, n = Inf, width = Inf, #' @describeIn print Print an entry within a partitioned `skim_df`. #' @export -print.one_skim_df <- function(x, n = Inf, width = Inf, n_extra = NULL, ...) { +print.one_skim_df <- function(x, + n = Inf, + width = Inf, + n_extra = NULL, + strip_metadata = TRUE, + ...) { variable_type <- paste("Variable type:", attr(x, "skim_type")) top_line <- cli::rule(line = 1, left = variable_type) - dots <- list(...) - out <- format(x, n = n, width = width, n_extra = n_extra, dots) - metadata <- grab_tibble_metadata(out) + out <- format(x, ..., n = n, width = width, n_extra = n_extra) + if (strip_metadata) { + metadata <- -1 * grab_tibble_metadata(out) + } else { + metadata <- seq_along(out) + } render_skim_body(top_line, out, metadata) } @@ -54,8 +70,8 @@ grab_tibble_metadata <- function(x) { } } -render_skim_body <- function(top_line, out, metadata) { - cat(paste0("\n", top_line), out[-metadata], sep = "\n") +render_skim_body <- function(top_line, out, metadata_to_remove) { + cat(paste0("\n", top_line), out[metadata_to_remove], sep = "\n") } #' @describeIn print Print a `skim_list`, a list of `skim_df` objects. diff --git a/man/print.Rd b/man/print.Rd index b27c9da4..b553cd04 100644 --- a/man/print.Rd +++ b/man/print.Rd @@ -9,10 +9,10 @@ \title{Print \code{skim} objects} \usage{ \method{print}{skim_df}(x, include_summary = TRUE, n = Inf, - width = Inf, n_extra = NULL, ...) + width = Inf, n_extra = NULL, strip_metadata = TRUE, ...) \method{print}{one_skim_df}(x, n = Inf, width = Inf, n_extra = NULL, - ...) + strip_metadata = TRUE, ...) \method{print}{skim_list}(x, n = Inf, width = Inf, n_extra = NULL, ...) @@ -38,6 +38,8 @@ default and always print all columns.} if the width is too small for the entire tibble. If \code{NULL}, the default, will print information about at most \code{tibble.max_extra_cols} extra columns.} +\item{strip_metadata}{Whether tibble metadata should be removed.} + \item{...}{Other arguments passed on to individual methods.} } \description{