From 434e0b72fb5a859fc07e236fe0c45ee734d6f3a9 Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Mon, 27 Dec 2021 16:28:54 -0800 Subject: [PATCH 1/6] Use pillar's formatting tools --- DESCRIPTION | 3 +- NAMESPACE | 6 +++- R/skim_print.R | 92 +++++++++++++++++++---------------------------- R/skimr-package.R | 4 --- man/print.Rd | 53 ++++----------------------- man/skim-obj.Rd | 5 +++ 6 files changed, 55 insertions(+), 108 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c8d86ca8..2d631e5f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -121,6 +121,7 @@ Imports: dplyr (>= 0.8.0), knitr (>= 1.2), magrittr (>= 1.5), + pillar, purrr, repr, rlang (>= 0.3.1), @@ -145,7 +146,7 @@ VignetteBuilder: Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Collate: 'deprecated.R' 'dplyr.R' diff --git a/NAMESPACE b/NAMESPACE index 147e1bba..7a1b59b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(ctl_new_pillar,one_skim_df) S3method(get_skimmers,AsIs) S3method(get_skimmers,Date) S3method(get_skimmers,POSIXct) @@ -18,7 +19,6 @@ 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) @@ -29,6 +29,7 @@ S3method(skim_by_type,data.frame) S3method(skim_by_type,data.table) S3method(skim_by_type,grouped_df) S3method(summary,skim_df) +S3method(tbl_format_header,one_skim_df) S3method(to_long,default) S3method(to_long,skim_df) S3method(vec_cast,skim_df.skim_df) @@ -62,6 +63,7 @@ export(get_sfl) export(get_skimmers) export(group_names) export(has_skim_type_attribute) +export(has_skimmers) export(has_skimr_attributes) export(has_type_column) export(has_variable_column) @@ -107,6 +109,8 @@ export(yank) importFrom(dplyr,mutate) importFrom(knitr,knit_print) importFrom(magrittr,"%>%") +importFrom(pillar,ctl_new_pillar) +importFrom(pillar,tbl_format_header) importFrom(repr,repr_text) importFrom(rlang,"%||%") importFrom(rlang,.data) diff --git a/R/skim_print.R b/R/skim_print.R index 8123d4fe..de0854dc 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -19,23 +19,11 @@ #' using [dplyr::select()] or [dplyr::summarize()] on a `skim_df`. In those #' cases, this method falls back to [tibble::print.tbl()]. #' -#' @section Controlling metadata behavior: -#' -#' On POSIX systems, `skimr` removes the tibble metadata when generating output. -#' On some platforms, this can lead to all output getting removed. To disable -#' that behavior, set either `strip_metadata = FALSE` when calling print or use -#' `options(skimr_strip_metadata = FALSE)`. The `crayon` package and the color -#' support within `tibble` is also a factor. If your `skimr` results tables are -#' empty you may need to run the following `options(crayon.enabled = FALSE)`. -#' #' @inheritParams tibble:::print.tbl #' @seealso [tibble::trunc_mat()] For a list of global options for customizing #' print formatting. [crayon::has_color()] for the variety of issues that #' affect tibble's color support. #' @param include_summary Whether a summary of the data frame should be printed -#' @param strip_metadata Whether tibble metadata should be removed. -#' @param rule_width Width of the cli rules in printed skim object. Defaults -#' to base::options()$width #' @param summary_rule_width Width of Data Summary cli rule, defaults to 40. #' @name print NULL @@ -47,71 +35,65 @@ print.skim_df <- function(x, n = Inf, width = Inf, n_extra = NULL, - strip_metadata = getOption( - "skimr_strip_metadata", FALSE - ), - rule_width = base::options()$width, summary_rule_width = 40, ...) { - withr::local_options(list(crayon.enabled = FALSE)) if (is_skim_df(x) && nrow(x) > 0) { if (include_summary) { print(summary(x), .summary_rule_width = summary_rule_width, ...) } by_type <- partition(x) purrr::map( - by_type, print, n, width, n_extra, strip_metadata, - .rule_width = rule_width, ... + by_type, + print, + width = width, + n = n, + ... ) - invisible(NULL) } else { NextMethod("print") } } -#' @describeIn print Print an entry within a partitioned `skim_df`. -#' @param .rule_width Width for the rule above the skim results for each type. -#' @param .width Width for the tibble for each type. + +# Methods for correctly formatting a a `one_skim_df`. We leverage the +# customiztion options in `pillar` for this. It divides the results into: a +# header, which we customize; a body, where we strip some values; and a footer, +# which we drop. For more details, see +# https://pillar.r-lib.org/articles/extending.html + +#' @importFrom pillar tbl_format_header #' @export -print.one_skim_df <- function(x, - n = Inf, - .width = Inf, - n_extra = NULL, - strip_metadata = getOption( - "skimr_strip_metadata", FALSE - ), - .rule_width = base::options()$width, - ...) { +tbl_format_header.one_skim_df <- function(x, setup, ...) { variable_type <- paste("Variable type:", attr(x, "skim_type")) - top_line <- cli::rule(line = 1, left = variable_type, width = .rule_width) - out <- format(x, ..., n = n, width = .width, n_extra = n_extra) - if (is.null(strip_metadata)) { - strip_metadata <- TRUE - } - if (strip_metadata) { - metadata <- -1 * grab_tibble_metadata(out) - } else { - metadata <- seq_along(out) - } - render_skim_body(top_line, out, metadata) -} - -grab_tibble_metadata <- function(x) { - if (crayon::has_color()) { - grep("^\\s*\\\033\\[38;5;\\d{3}m[#\\*]", x) - } else { - grep("^\\s*[#\\*]", x) - } + rule <- cli::rule( + line = 1, + left = variable_type, + width = getOption("width", 80) + ) + # Add an empty line before the rule + c("", rule) } -render_skim_body <- function(top_line, out, metadata_to_remove) { - cat(paste0("\n", top_line), out[metadata_to_remove], sep = "\n") +#' @importFrom pillar ctl_new_pillar +#' @export +ctl_new_pillar.one_skim_df <- function(controller, + x, + width, + ..., + title = NULL) { + out <- NextMethod() + out$type <- NULL + out } #' @describeIn print Print a `skim_list`, a list of `skim_df` objects. #' @export -print.skim_list <- function(x, n = Inf, width = Inf, n_extra = NULL, - .rule_width = base::options()$width, ...) { +print.skim_list <- function(x, + n = Inf, + width = Inf, + n_extra = NULL, + .rule_width = getOption("width", 80), + ...) { nms <- names(x) attributes(x) <- NULL print(rlang::set_names(x, nms), rule_width = .rule_width) diff --git a/R/skimr-package.R b/R/skimr-package.R index de18a4ab..74df0771 100644 --- a/R/skimr-package.R +++ b/R/skimr-package.R @@ -16,10 +16,6 @@ #' @docType package NULL -.onLoad <- function(libname, pkgname) { - options(skimr_strip_metadata = .Platform$OS.type != "windows") -} - # Imports ----------------------------------------------------------------- diff --git a/man/print.Rd b/man/print.Rd index efe63f4c..222a0cc7 100644 --- a/man/print.Rd +++ b/man/print.Rd @@ -3,7 +3,6 @@ \name{print} \alias{print} \alias{print.skim_df} -\alias{print.one_skim_df} \alias{print.skim_list} \alias{print.summary_skim_df} \title{Print \code{skim} objects} @@ -14,28 +13,16 @@ n = Inf, width = Inf, n_extra = NULL, - strip_metadata = getOption("skimr_strip_metadata", FALSE), - rule_width = base::options()$width, summary_rule_width = 40, ... ) -\method{print}{one_skim_df}( - x, - n = Inf, - .width = Inf, - n_extra = NULL, - strip_metadata = getOption("skimr_strip_metadata", FALSE), - .rule_width = base::options()$width, - ... -) - \method{print}{skim_list}( x, n = Inf, width = Inf, n_extra = NULL, - .rule_width = base::options()$width, + .rule_width = getOption("width", 80), ... ) @@ -47,31 +34,16 @@ \item{include_summary}{Whether a summary of the data frame should be printed} \item{n}{Number of rows to show. If \code{NULL}, the default, will print all rows -if less than option \code{tibble.print_max}. Otherwise, will print -\code{tibble.print_min} rows.} +if less than the \code{print_max} \link[pillar:pillar_options]{option}. +Otherwise, will print as many rows as specified by the +\code{print_min} \link[pillar:pillar_options]{option}.} \item{width}{Width of text output to generate. This defaults to \code{NULL}, which -means use \code{getOption("tibble.width")} or (if also \code{NULL}) -\code{getOption("width")}; the latter displays only the columns that fit on one -screen. You can also set \code{options(tibble.width = Inf)} to override this -default and always print all columns, this may be slow for very wide tibbles.} - -\item{n_extra}{Number of extra columns to print abbreviated information for, -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{rule_width}{Width of the cli rules in printed skim object. Defaults -to base::options()$width} +means use the \code{width} \link[pillar:pillar_options]{option}.} \item{summary_rule_width}{Width of Data Summary cli rule, defaults to 40.} -\item{...}{Other arguments passed on to individual methods.} - -\item{.width}{Width for the tibble for each type.} - -\item{.rule_width}{Width for the rule above the skim results for each type.} +\item{...}{Passed on to \code{\link[=tbl_format_setup]{tbl_format_setup()}}.} \item{.summary_rule_width}{the width for the main rule above the summary.} } @@ -83,8 +55,6 @@ methods for \code{knitr}/ \code{rmarkdown} documents is also provided. \itemize{ \item \code{skim_df}: Print a skimmed data frame (\code{skim_df} from \code{\link[=skim]{skim()}}). -\item \code{one_skim_df}: Print an entry within a partitioned \code{skim_df}. - \item \code{skim_list}: Print a \code{skim_list}, a list of \code{skim_df} objects. \item \code{summary_skim_df}: Print method for a \code{summary_skim_df} object. @@ -110,17 +80,6 @@ using \code{\link[dplyr:select]{dplyr::select()}} or \code{\link[dplyr:summarise cases, this method falls back to \code{\link[tibble:formatting]{tibble::print.tbl()}}. } -\section{Controlling metadata behavior}{ - - -On POSIX systems, \code{skimr} removes the tibble metadata when generating output. -On some platforms, this can lead to all output getting removed. To disable -that behavior, set either \code{strip_metadata = FALSE} when calling print or use -\code{options(skimr_strip_metadata = FALSE)}. The \code{crayon} package and the color -support within \code{tibble} is also a factor. If your \code{skimr} results tables are -empty you may need to run the following \code{options(crayon.enabled = FALSE)}. -} - \seealso{ \code{\link[tibble:trunc_mat]{tibble::trunc_mat()}} For a list of global options for customizing print formatting. \code{\link[crayon:has_color]{crayon::has_color()}} for the variety of issues that diff --git a/man/skim-obj.Rd b/man/skim-obj.Rd index bf23ccc5..960af910 100644 --- a/man/skim-obj.Rd +++ b/man/skim-obj.Rd @@ -6,6 +6,7 @@ \alias{has_variable_column} \alias{has_skimr_attributes} \alias{has_skim_type_attribute} +\alias{has_skimmers} \alias{is_data_frame} \alias{is_skim_df} \alias{is_one_skim_df} @@ -24,6 +25,8 @@ has_skimr_attributes(object) has_skim_type_attribute(object) +has_skimmers(object) + is_data_frame(object) is_skim_df(object) @@ -77,6 +80,8 @@ more useful when throwing errors. \item \code{has_skim_type_attribute}: Does the object have a \code{skim_type} attribute? This makes it a \code{one_skim_df}. +\item \code{has_skimmers}: Does the object have skimmers? + \item \code{is_data_frame}: Is the object a data frame? \item \code{is_skim_df}: Is the object a \code{skim_df}? From 66170be3ed8f4fba86594ef4a70d4a98d7eb16d8 Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Mon, 27 Dec 2021 16:29:24 -0800 Subject: [PATCH 2/6] Update README --- README.Rmd | 25 ------------- README.md | 106 +++++++++++++++++++++++++---------------------------- 2 files changed, 50 insertions(+), 81 deletions(-) diff --git a/README.Rmd b/README.Rmd index 3fad1ded..f0e4bc1a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -254,31 +254,6 @@ Displays in documents of different types will vary. For example, one user found that the font "Yu Gothic UI Semilight" produced consistent results for Microsoft Word and Libre Office Write. -### Stripping metadata and empty results tables - -In POSIX systems, `skimr` tries to remove the tibble metadata when producing -the results. A complicating factor is tibble's color support, which depends -on environment settings. In particular, not all Windows terminals support -colors in the way that tibble expects. - -So, by default, we disable removing metadata on windows. You can turn this -feature on with an option. Either set it when calling print or globally. - -```{r, eval = FALSE} -skimmed <- skim(chickwts) -print(skimmed, strip_metadata = TRUE) -options(skimr_strip_metadata = TRUE) -``` - -Separately, you might need to check the option `crayon.enabled`. Similarly, if -your skimr results tables are empty you may need to run the following - -```{r, eval = FALSE} -options(crayon.enabled = FALSE) -``` - -You need to do this one time per session. - ## Inspirations * [TextPlots](https://github.com/sunetos/TextPlots.jl) for use of Braille diff --git a/README.md b/README.md index eb0d9027..b2a09d77 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ Skim statistics in the console ## 1 feed 0 1 FALSE 6 soy: 14, cas: 12, lin: 12, sun: 12 ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 weight 0 1 261. 78.1 108 204. 258 324. 423 ▆▆▇▇▃ + ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 weight 0 1 261. 78.1 108 204. 258 324. 423 ▆▆▇▇▃ ### Presentation is in a compact horizontal format: @@ -108,11 +108,11 @@ Skim statistics in the console ## 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ - ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ - ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ - ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ ### Built in support for strings, lists and other column classes @@ -132,15 +132,15 @@ Skim statistics in the console ## Group variables None ## ## ── Variable type: character ──────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate min max empty n_unique whitespace - ## 1 name 0 1 3 21 0 87 0 - ## 2 hair_color 5 0.943 4 13 0 12 0 - ## 3 skin_color 0 1 3 19 0 31 0 - ## 4 eye_color 0 1 3 13 0 15 0 - ## 5 sex 4 0.954 4 14 0 4 0 - ## 6 gender 4 0.954 8 9 0 2 0 - ## 7 homeworld 10 0.885 4 14 0 48 0 - ## 8 species 4 0.954 3 14 0 37 0 + ## skim_variable n_missing complete_rate min max empty n_unique whitespace + ## 1 name 0 1 3 21 0 87 0 + ## 2 hair_color 5 0.943 4 13 0 12 0 + ## 3 skin_color 0 1 3 19 0 31 0 + ## 4 eye_color 0 1 3 13 0 15 0 + ## 5 sex 4 0.954 4 14 0 4 0 + ## 6 gender 4 0.954 8 9 0 2 0 + ## 7 homeworld 10 0.885 4 14 0 48 0 + ## 8 species 4 0.954 3 14 0 37 0 ## ## ── Variable type: list ───────────────────────────────────────────────────────────────────────────── ## skim_variable n_missing complete_rate n_unique min_length max_length @@ -149,10 +149,10 @@ Skim statistics in the console ## 3 starships 0 1 17 0 5 ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 height 6 0.931 174. 34.8 66 167 180 191 264 ▁▁▇▅▁ - ## 2 mass 28 0.678 97.3 169. 15 55.6 79 84.5 1358 ▇▁▁▁▁ - ## 3 birth_year 44 0.494 87.6 155. 8 35 52 72 896 ▇▁▁▁▁ + ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 height 6 0.931 174. 34.8 66 167 180 191 264 ▁▁▇▅▁ + ## 2 mass 28 0.678 97.3 169. 15 55.6 79 84.5 1358 ▇▁▁▁▁ + ## 3 birth_year 44 0.494 87.6 155. 8 35 52 72 896 ▇▁▁▁▁ ### Has a useful summary function @@ -187,9 +187,9 @@ Skim statistics in the console ## Group variables None ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ - ## 2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + ## 2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ ### Handles grouped data @@ -212,19 +212,19 @@ Skim statistics in the console ## Group variables Species ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 5.8 ▃▃▇▅▁ - ## 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 7 ▂▇▆▃▃ - ## 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 7.9 ▁▃▇▃▂ - ## 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 3.68 4.4 ▁▃▇▅▂ - ## 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 3 3.4 ▁▅▆▇▂ - ## 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 3.18 3.8 ▂▆▇▅▁ - ## 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 1.58 1.9 ▁▃▇▃▁ - ## 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 4.6 5.1 ▂▂▇▇▆ - ## 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 5.88 6.9 ▃▇▇▃▂ - ## 10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 0.3 0.6 ▇▂▂▁▁ - ## 11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 1.5 1.8 ▅▇▃▆▁ - ## 12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 2.3 2.5 ▂▇▆▅▇ + ## skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 5.8 ▃▃▇▅▁ + ## 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 7 ▂▇▆▃▃ + ## 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 7.9 ▁▃▇▃▂ + ## 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 3.68 4.4 ▁▃▇▅▂ + ## 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 3 3.4 ▁▅▆▇▂ + ## 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 3.18 3.8 ▂▆▇▅▁ + ## 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 1.58 1.9 ▁▃▇▃▁ + ## 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 4.6 5.1 ▂▂▇▇▆ + ## 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 5.88 6.9 ▃▇▇▃▂ + ## 10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 0.3 0.6 ▇▂▂▁▁ + ## 11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 1.5 1.8 ▅▇▃▆▁ + ## 12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 2.3 2.5 ▂▇▆▅▇ ### Behaves nicely in pipelines @@ -244,8 +244,8 @@ Skim statistics in the console ## Group variables None ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── - ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + ## 1 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ Knitted results --------------- @@ -468,28 +468,22 @@ Displays in documents of different types will vary. For example, one user found that the font “Yu Gothic UI Semilight” produced consistent results for Microsoft Word and Libre Office Write. -### Stripping metadata and empty results tables - -In POSIX systems, `skimr` tries to remove the tibble metadata when -producing the results. A complicating factor is tibble’s color support, -which depends on environment settings. In particular, not all Windows -terminals support colors in the way that tibble expects. - -So, by default, we disable removing metadata on windows. You can turn -this feature on with an option. Either set it when calling print or -globally. +Inspirations +------------ - skimmed <- skim(chickwts) - print(skimmed, strip_metadata = TRUE) - options(skimr_strip_metadata = TRUE) +- [TextPlots](https://github.com/sunetos/TextPlots.jl) for use of + Braille characters -Separately, you might need to check the option `crayon.enabled`. -Similarly, if your skimr results tables are empty you may need to run -the following +- [spark](https://github.com/holman/spark) for use of block + characters. - options(crayon.enabled = FALSE) +The earliest use of unicode characters to generate sparklines appears to +be [from +2009](https://blog.jonudell.net/2009/01/13/fuel-prices-and-pageviews/). -You need to do this one time per session. +Exercising these ideas to their fullest requires a font with good +support for block drawing characters. +[PragamataPro](https://fsd.it/shop/fonts/pragmatapro/) is one such font. Contributing ------------ From 01f8dca977ddb2fc1f633ce8c2318179a3455a7b Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Mon, 27 Dec 2021 22:29:56 -0800 Subject: [PATCH 3/6] Remove unneeded arguments --- man/print.Rd | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/man/print.Rd b/man/print.Rd index 222a0cc7..98751239 100644 --- a/man/print.Rd +++ b/man/print.Rd @@ -12,19 +12,11 @@ include_summary = TRUE, n = Inf, width = Inf, - n_extra = NULL, summary_rule_width = 40, ... ) -\method{print}{skim_list}( - x, - n = Inf, - width = Inf, - n_extra = NULL, - .rule_width = getOption("width", 80), - ... -) +\method{print}{skim_list}(x, n = Inf, width = Inf, ...) \method{print}{summary_skim_df}(x, .summary_rule_width = 40, ...) } From 4deeb6f0832a6c1f05e7754e3edea9b1b1484d12 Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Mon, 27 Dec 2021 22:30:20 -0800 Subject: [PATCH 4/6] Update test output --- R/skim_print.R | 5 +-- .../data.table/summary_DF_factors.txt | 8 ++-- .../data.table/summary_DT_factors.txt | 8 ++-- .../data.table/summary_DT_factors_no_key.txt | 8 ++-- .../data.table/summary_DT_letters.txt | 4 +- .../data.table/summary_tibble_factors.txt | 8 ++-- tests/testthat/dplyr/arrange.txt | 10 ++--- tests/testthat/dplyr/filter-skim.txt | 10 ++--- tests/testthat/dplyr/mutate-skim.txt | 10 ++--- tests/testthat/dplyr/slice.txt | 6 +-- tests/testthat/helper-expectations.R | 2 + tests/testthat/print/default.txt | 10 ++--- tests/testthat/print/groups.txt | 26 ++++++------ tests/testthat/print/list.txt | 10 ++--- tests/testthat/print/no-hist.txt | 10 ++--- tests/testthat/print/repr.txt | 15 +++---- tests/testthat/print/smaller.txt | 20 +++++----- tests/testthat/skim_tee/grouped.txt | 16 ++++---- tests/testthat/skim_tee/sepal.txt | 9 ++--- tests/testthat/skim_tee/skim_tee.txt | 6 +-- tests/testthat/test-skim_print.R | 40 ------------------- 21 files changed, 95 insertions(+), 146 deletions(-) diff --git a/R/skim_print.R b/R/skim_print.R index de0854dc..1b6a82f1 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -34,7 +34,6 @@ print.skim_df <- function(x, include_summary = TRUE, n = Inf, width = Inf, - n_extra = NULL, summary_rule_width = 40, ...) { if (is_skim_df(x) && nrow(x) > 0) { @@ -91,12 +90,10 @@ ctl_new_pillar.one_skim_df <- function(controller, print.skim_list <- function(x, n = Inf, width = Inf, - n_extra = NULL, - .rule_width = getOption("width", 80), ...) { nms <- names(x) attributes(x) <- NULL - print(rlang::set_names(x, nms), rule_width = .rule_width) + print(rlang::set_names(x, nms)) } diff --git a/tests/testthat/data.table/summary_DF_factors.txt b/tests/testthat/data.table/summary_DF_factors.txt index 6c872484..a949786f 100644 --- a/tests/testthat/data.table/summary_DF_factors.txt +++ b/tests/testthat/data.table/summary_DF_factors.txt @@ -12,13 +12,13 @@ ________________________ Group variables None -- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 + skim_variable n_missing complete_rate min max empty n_unique whitespace +1 abc 0 1 1 1 0 26 0 -- Variable type: factor --------------------------------------------------------------------------- skim_variable n_missing complete_rate ordered n_unique top_counts 1 grps 0 1 FALSE 2 AA: 18, BB: 8 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_factors.txt b/tests/testthat/data.table/summary_DT_factors.txt index 67a42b0a..016d107b 100644 --- a/tests/testthat/data.table/summary_DT_factors.txt +++ b/tests/testthat/data.table/summary_DT_factors.txt @@ -13,13 +13,13 @@ ________________________ Group variables None -- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 + skim_variable n_missing complete_rate min max empty n_unique whitespace +1 abc 0 1 1 1 0 26 0 -- Variable type: factor --------------------------------------------------------------------------- skim_variable n_missing complete_rate ordered n_unique top_counts 1 grps 0 1 FALSE 2 AA: 18, BB: 8 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_factors_no_key.txt b/tests/testthat/data.table/summary_DT_factors_no_key.txt index 13051dc2..a9f68584 100644 --- a/tests/testthat/data.table/summary_DT_factors_no_key.txt +++ b/tests/testthat/data.table/summary_DT_factors_no_key.txt @@ -13,13 +13,13 @@ ________________________ Group variables None -- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 + skim_variable n_missing complete_rate min max empty n_unique whitespace +1 abc 0 1 1 1 0 26 0 -- Variable type: factor --------------------------------------------------------------------------- skim_variable n_missing complete_rate ordered n_unique top_counts 1 grps 0 1 FALSE 2 AA: 18, BB: 8 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_letters.txt b/tests/testthat/data.table/summary_DT_letters.txt index c9dbec7c..94461766 100644 --- a/tests/testthat/data.table/summary_DT_letters.txt +++ b/tests/testthat/data.table/summary_DT_letters.txt @@ -11,5 +11,5 @@ ________________________ Group variables None -- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 + skim_variable n_missing complete_rate min max empty n_unique whitespace +1 abc 0 1 1 1 0 26 0 diff --git a/tests/testthat/data.table/summary_tibble_factors.txt b/tests/testthat/data.table/summary_tibble_factors.txt index fe9db5b4..91d8d1fc 100644 --- a/tests/testthat/data.table/summary_tibble_factors.txt +++ b/tests/testthat/data.table/summary_tibble_factors.txt @@ -12,13 +12,13 @@ ________________________ Group variables None -- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 + skim_variable n_missing complete_rate min max empty n_unique whitespace +1 abc 0 1 1 1 0 26 0 -- Variable type: factor --------------------------------------------------------------------------- skim_variable n_missing complete_rate ordered n_unique top_counts 1 grps 0 1 FALSE 2 AA: 18, BB: 8 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/dplyr/arrange.txt b/tests/testthat/dplyr/arrange.txt index 4e033091..542a5552 100644 --- a/tests/testthat/dplyr/arrange.txt +++ b/tests/testthat/dplyr/arrange.txt @@ -15,8 +15,8 @@ Group variables None 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -3 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +3 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/dplyr/filter-skim.txt b/tests/testthat/dplyr/filter-skim.txt index af289ff7..66ccfcf1 100644 --- a/tests/testthat/dplyr/filter-skim.txt +++ b/tests/testthat/dplyr/filter-skim.txt @@ -10,8 +10,8 @@ ________________________ Group variables None -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/dplyr/mutate-skim.txt b/tests/testthat/dplyr/mutate-skim.txt index f141ca76..b8b34668 100644 --- a/tests/testthat/dplyr/mutate-skim.txt +++ b/tests/testthat/dplyr/mutate-skim.txt @@ -15,8 +15,8 @@ Group variables None 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist mean2 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ 34.1 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ 9.35 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ 14.1 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ 1.44 + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist mean2 +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ 34.1 +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ 9.35 +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ 14.1 +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ 1.44 diff --git a/tests/testthat/dplyr/slice.txt b/tests/testthat/dplyr/slice.txt index 081ebbab..298a3bd8 100644 --- a/tests/testthat/dplyr/slice.txt +++ b/tests/testthat/dplyr/slice.txt @@ -15,6 +15,6 @@ Group variables None 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ diff --git a/tests/testthat/helper-expectations.R b/tests/testthat/helper-expectations.R index 3e135ee7..714891d0 100644 --- a/tests/testthat/helper-expectations.R +++ b/tests/testthat/helper-expectations.R @@ -71,10 +71,12 @@ expect_matches_file <- function(object, "skimr_skip_on_cran", TRUE ), + width = 100, ...) { if (skip_on_windows) testthat::skip_on_os("windows") if (skip_on_windows) testthat::skip_if_not(l10n_info()$`UTF-8`) if (skip_on_cran) testthat::skip_on_cran() + withr::local_options(list(crayon.enabled = FALSE, width = width)) act <- testthat::quasi_label(rlang::enquo(object), NULL) if (!file.exists(file)) { diff --git a/tests/testthat/print/default.txt b/tests/testthat/print/default.txt index 7d69c842..bd422226 100644 --- a/tests/testthat/print/default.txt +++ b/tests/testthat/print/default.txt @@ -15,8 +15,8 @@ Group variables None 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/groups.txt b/tests/testthat/print/groups.txt index a536fd11..daec8fd2 100644 --- a/tests/testthat/print/groups.txt +++ b/tests/testthat/print/groups.txt @@ -10,16 +10,16 @@ ________________________ Group variables Species -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 5.8 ▃▃▇▅▁ - 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 7 ▂▇▆▃▃ - 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 7.9 ▁▃▇▃▂ - 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 3.68 4.4 ▁▃▇▅▂ - 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 3 3.4 ▁▅▆▇▂ - 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 3.18 3.8 ▂▆▇▅▁ - 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 1.58 1.9 ▁▃▇▃▁ - 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 4.6 5.1 ▂▂▇▇▆ - 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 5.88 6.9 ▃▇▇▃▂ -10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 0.3 0.6 ▇▂▂▁▁ -11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 1.5 1.8 ▅▇▃▆▁ -12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 2.3 2.5 ▂▇▆▅▇ + skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 5.8 ▃▃▇▅▁ + 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 7 ▂▇▆▃▃ + 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 7.9 ▁▃▇▃▂ + 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 3.68 4.4 ▁▃▇▅▂ + 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 3 3.4 ▁▅▆▇▂ + 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 3.18 3.8 ▂▆▇▅▁ + 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 1.58 1.9 ▁▃▇▃▁ + 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 4.6 5.1 ▂▂▇▇▆ + 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 5.88 6.9 ▃▇▇▃▂ +10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 0.3 0.6 ▇▂▂▁▁ +11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 1.5 1.8 ▅▇▃▆▁ +12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 2.3 2.5 ▂▇▆▅▇ diff --git a/tests/testthat/print/list.txt b/tests/testthat/print/list.txt index 0a4a59f0..f30eae92 100644 --- a/tests/testthat/print/list.txt +++ b/tests/testthat/print/list.txt @@ -7,9 +7,9 @@ $factor $numeric -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/no-hist.txt b/tests/testthat/print/no-hist.txt index 478b26be..e78eceb4 100644 --- a/tests/testthat/print/no-hist.txt +++ b/tests/testthat/print/no-hist.txt @@ -15,8 +15,8 @@ Group variables None 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 diff --git a/tests/testthat/print/repr.txt b/tests/testthat/print/repr.txt index 614f08f7..d5960f2c 100644 --- a/tests/testthat/print/repr.txt +++ b/tests/testthat/print/repr.txt @@ -17,13 +17,8 @@ Group variables None 1 set: 50, ver: 50, vir: 50 -- Variable type: numeric ------------------------------------------------------ - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 - p100 hist -1 7.9 ▆▇▇▅▂ -2 4.4 ▁▆▇▂▁ -3 6.9 ▇▁▆▇▂ -4 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/smaller.txt b/tests/testthat/print/smaller.txt index 04086f5a..633580d8 100644 --- a/tests/testthat/print/smaller.txt +++ b/tests/testthat/print/smaller.txt @@ -17,13 +17,13 @@ Group variables None 1 3 set: 50, ver: 50, vir: 50 -- Variable type: numeric ------------------------ - skim_variable n_missing complete_rate mean -1 Sepal.Length 0 1 5.84 -2 Sepal.Width 0 1 3.06 -3 Petal.Length 0 1 3.76 -4 Petal.Width 0 1 1.20 - sd p0 p25 p50 p75 p100 hist -1 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + skim_variable n_missing complete_rate mean sd +1 Sepal.Length 0 1 5.84 0.828 +2 Sepal.Width 0 1 3.06 0.436 +3 Petal.Length 0 1 3.76 1.77 +4 Petal.Width 0 1 1.20 0.762 + p0 p25 p50 p75 p100 hist +1 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 2 2.8 3 3.3 4.4 ▁▆▇▂▁ +3 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ +4 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/skim_tee/grouped.txt b/tests/testthat/skim_tee/grouped.txt index b92bddc3..13bb600e 100644 --- a/tests/testthat/skim_tee/grouped.txt +++ b/tests/testthat/skim_tee/grouped.txt @@ -10,11 +10,11 @@ ________________________ Group variables Species ── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable Species n_missing complete_rate mean sd p0 p25 p50 -1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 -2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 -3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 - p75 p100 -1 5.2 5.8 -2 6.3 7 -3 6.9 7.9 + skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 +1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 +2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 +3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 + p100 +1 5.8 +2 7 +3 7.9 diff --git a/tests/testthat/skim_tee/sepal.txt b/tests/testthat/skim_tee/sepal.txt index 0566e54f..162011cc 100644 --- a/tests/testthat/skim_tee/sepal.txt +++ b/tests/testthat/skim_tee/sepal.txt @@ -10,9 +10,6 @@ ________________________ Group variables None ── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 - p100 hist -1 7.9 ▆▇▇▅▂ -2 4.4 ▁▆▇▂▁ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ +2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ diff --git a/tests/testthat/skim_tee/skim_tee.txt b/tests/testthat/skim_tee/skim_tee.txt index f48c830c..7fac0954 100644 --- a/tests/testthat/skim_tee/skim_tee.txt +++ b/tests/testthat/skim_tee/skim_tee.txt @@ -17,7 +17,5 @@ Group variables None 1 soy: 14, cas: 12, lin: 12, sun: 12 ── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 -1 weight 0 1 261. 78.1 108 204. 258 324. - p100 hist -1 423 ▆▆▇▇▃ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist +1 weight 0 1 261. 78.1 108 204. 258 324. 423 ▆▆▇▇▃ diff --git a/tests/testthat/test-skim_print.R b/tests/testthat/test-skim_print.R index 66f6d150..c47446b2 100644 --- a/tests/testthat/test-skim_print.R +++ b/tests/testthat/test-skim_print.R @@ -107,25 +107,6 @@ test_that("Metadata is stripped from smaller consoles", { expect_print_matches_file(skimmed, "print/smaller.txt", width = 50) }) -test_that("Crayon is supported", { - skip("Temporary skip due to issues with crayon support on some platforms") - withr::local_options(list(cli.unicode = FALSE)) - withr::with_options(list(crayon.enabled = TRUE), { - with_mock( - .env = "skimr", - render_skim_body = function(...) { - paste0(..., sep = "\n", collapse = "\n") - }, - { - skimmed <- skim(iris) - numeric <- yank(skimmed, "numeric") - rendered <- print(numeric) - } - ) - expect_match(rendered, "\\\033") - }) -}) - test_that("skimr creates appropriate output for Jupyter", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) @@ -133,24 +114,3 @@ test_that("skimr creates appropriate output for Jupyter", { input <- testthat::capture_output(repr_text(skimmed)) expect_matches_file(input, "print/repr.txt") }) - -test_that("Metadata can be included: print", { - withr::local_options(list(cli.unicode = FALSE)) - skip_if_not(l10n_info()$`UTF-8`) - skimmed <- skim(iris) - expect_print_matches_file( - skimmed, - "print/strip.txt", - strip_metadata = FALSE, - width = 80 - ) -}) - -test_that("Metadata can be included: option", { - skip_if_not(l10n_info()$`UTF-8`) - withr::local_options(list(cli.unicode = FALSE)) - skimmed <- skim(iris) - withr::with_options(list(skimr_strip_metadata = FALSE), { - expect_print_matches_file(skimmed, "print/strip-opt.txt", width = 80) - }) -}) From 61e4a010141eb819c69171b10ee1950f8b1a46d6 Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Fri, 31 Dec 2021 17:50:04 -0800 Subject: [PATCH 5/6] Refactor summary() to separate print and compute. --- NAMESPACE | 1 + R/skim_print.R | 27 +++++------ R/summary.R | 88 +++++++++++++++++++++++------------ tests/testthat/test-summary.R | 18 ++++--- 4 files changed, 83 insertions(+), 51 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7a1b59b1..0f4e23c6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(ctl_new_pillar,one_skim_df) +S3method(format,summary_skim_df) S3method(get_skimmers,AsIs) S3method(get_skimmers,Date) S3method(get_skimmers,POSIXct) diff --git a/R/skim_print.R b/R/skim_print.R index 1b6a82f1..1386c14b 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -101,11 +101,11 @@ print.skim_list <- function(x, #' @param .summary_rule_width the width for the main rule above the summary. #' @export print.summary_skim_df <- function(x, .summary_rule_width = 40, ...) { - cat(paste0(cli::rule( - line = 1, left = "Data Summary", - width = .summary_rule_width - ), "\n")) - print.table(x) + with_title <- c( + cli::rule(line = 1, left = "Data Summary", width = .summary_rule_width), + format(x) + ) + writeLines(with_title) } #' Provide a default printing method for knitr. @@ -139,14 +139,7 @@ knit_print.skim_df <- function(x, options = NULL, ...) { if (is_skim_df(x) && nrow(x) > 0) { if (options$skimr_include_summary %||% TRUE) { summary_stats <- summary(x) - - kabled <- knitr::kable( - summary_stats, - table.attr = "style='width: auto;' - class='table table-condensed'", - col.names = c(" "), - caption = "Data summary" - ) + kabled <- knit_print(summary_stats) } else { kabled <- c() } @@ -193,11 +186,15 @@ knit_print.one_skim_df <- function(x, options = NULL, ...) { #' @describeIn knit_print Default `knitr` print for `skim_df` summaries. #' @export knit_print.summary_skim_df <- function(x, options = NULL, ...) { + summary_mat <- cbind( + get_summary_dnames(x), + get_summary_values(x), + deparse.level = 0 + ) kabled <- knitr::kable( - x, + summary_mat, table.attr = "style='width: auto;' class='table table-condensed'", - col.names = c(" "), caption = "Data summary" ) diff --git a/R/summary.R b/R/summary.R index 69aa8482..6dc0fed6 100644 --- a/R/summary.R +++ b/R/summary.R @@ -13,18 +13,10 @@ summary.skim_df <- function(object, ...) { if (is.null(object)) { stop("dataframe is null.") } - data_name <- df_name(object) - data_name <- ifelse(data_name %in% c("`.`", ".data"), "Piped data", data_name) - data_name <- gsub("`", "", data_name) - data_name <- ifelse(nchar(data_name) > 25, - paste0(substring(data_name, 1, 25), "..."), - data_name - ) - duplicated <- duplicated(object$skim_variable) counts <- table(type = object$skim_type[!duplicated]) types <- dimnames(counts)[[1]] - types <- paste0(" ", types) + possible_names <- group_names(object) possible_groups <- if (length(possible_names) > 0) { paste(possible_names, collapse = ", ") @@ -32,28 +24,66 @@ summary.skim_df <- function(object, ...) { "None" } - summary_object <- c( - data_name, - data_rows(object), - data_cols(object), - if (!is.na(dt_key(object))) dt_key(object), - " ", - " ", - unname(counts), - " ", - possible_groups + structure( + list( + data_name = process_data_name(object), + counts = counts, + types = types, + possible_groups = possible_groups, + dt_key = dt_key(object), + data_rows = data_rows(object), + data_cols = data_cols(object) + ), + class = "summary_skim_df" ) +} - summary_object <- array(summary_object, dim = c(length(summary_object), 1)) - dnames <- c( - "Name", "Number of rows ", "Number of columns ", - if (!is.na(dt_key(object))) "Key", "_______________________ ", - "Column type frequency: ", types, "________________________ ", - "Group variables" +process_data_name <- function(object) { + raw_name <- df_name(object) + no_ticks <- gsub("`", "", raw_name) + if (no_ticks %in% c(".", ".data")) { + "Piped data" + } else if(nchar(no_ticks) > 25) { + paste0(substring(no_ticks, 1, 25), "...") + } else { + no_ticks + } +} + +#' @export +format.summary_skim_df <- function(x, ...) { + dnames <- c("", get_summary_dnames(x)) + summary_values <- c("Values", get_summary_values(x)) + paste( + format(dnames), + format(summary_values) ) +} - summary_object <- as.table(summary_object) - dimnames(summary_object) <- list(dnames, c("Values")) - class(summary_object) <- c("summary_skim_df", "table") - summary_object +get_summary_dnames <- function(summary_object) { + c( + "Name", + "Number of rows ", + "Number of columns ", + if (!is.na(summary_object$dt_key)) "Key", + "_______________________ ", + "Column type frequency: ", + paste0(" ", summary_object$types), + "________________________ ", + "Group variables" + ) } + +get_summary_values <- function(summary_object) { + c( + summary_object$data_name, + summary_object$data_rows, + summary_object$data_cols, + if (!is.na(summary_object$dt_key)) summary_object$dt_key, + " ", + " ", + unname(summary_object$counts), + " ", + summary_object$possible_groups + ) +} \ No newline at end of file diff --git a/tests/testthat/test-summary.R b/tests/testthat/test-summary.R index 37fd6525..91f9f3b8 100644 --- a/tests/testthat/test-summary.R +++ b/tests/testthat/test-summary.R @@ -3,13 +3,17 @@ test_that("Summary creates the correct summary object", { # Test it creates the correct 4 parts skim_input <- skim(iris) summary_input <- summary(skim_input) - expect_equal(rownames(summary_input), c( - "Name", "Number of rows ", "Number of columns ", - "_______________________ ", - "Column type frequency: ", " factor", " numeric", - "________________________ ", - "Group variables" - )) + expect_named( + summary_input, + c( + "data_name", "counts", "types", "possible_groups", + "dt_key", "data_rows", "data_cols" + ) + ) + expect_identical(summary_input$data_name, "iris") + expect_identical(summary_input$types, c("factor", "numeric")) + expect_identical(summary_input$data_rows, 150L) + expect_identical(summary_input$data_cols, 5L) }) test_that("The summary print method prints the correct object", { From be19a6a95c6d3fb6aa80a78bab255c2d048b440a Mon Sep 17 00:00:00 2001 From: "michael.quinn@aya.yale.edu" Date: Fri, 31 Dec 2021 20:26:09 -0800 Subject: [PATCH 6/6] Style --- R/summary.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/summary.R b/R/summary.R index 6dc0fed6..bba5fe50 100644 --- a/R/summary.R +++ b/R/summary.R @@ -43,7 +43,7 @@ process_data_name <- function(object) { no_ticks <- gsub("`", "", raw_name) if (no_ticks %in% c(".", ".data")) { "Piped data" - } else if(nchar(no_ticks) > 25) { + } else if (nchar(no_ticks) > 25) { paste0(substring(no_ticks, 1, 25), "...") } else { no_ticks @@ -86,4 +86,4 @@ get_summary_values <- function(summary_object) { " ", summary_object$possible_groups ) -} \ No newline at end of file +}