Skip to content

Commit

Permalink
Merge pull request #496 from ropensci/skim-no-charts
Browse files Browse the repository at this point in the history
Skim no charts
  • Loading branch information
michaelquinn32 authored Oct 26, 2019
2 parents 5b8ace7 + d727ef6 commit 2f5c322
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 188 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.pre-commit-config\.yaml$
^\.travis\.yml$
^\\inst\\doc\\other_docs\\blog\.html$
^\\inst\\doc\\other_docs\\blog\.Rmd$
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export(skim_tee)
export(skim_to_list)
export(skim_to_wide)
export(skim_with)
export(skim_without_charts)
export(sorted_count)
export(starts_with)
export(to_long)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ displayed digits by adding the `skimr_digits` option to your code chunk.
job on big data sets with lots of different columns.
* New statistic for character variables counting the number of rows that are
completely made up of white space.
* We now export `skim_without_charts()` as a fallback for when unicode support
is not possible.

### BUG FIXES

Expand Down
29 changes: 21 additions & 8 deletions R/skim.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Skim a data frame, getting useful summary statistics
#'
#' `skim()` is an alternative to [`summary()`], quickly providing a broad
#' `skim()` is an alternative to [summary()], quickly providing a broad
#' overview of a data frame. It handles data of all types, dispatching a
#' different set of summary functions based on the types of columns in the data
#' frame.
Expand Down Expand Up @@ -32,17 +32,20 @@
#'
#' @section Customizing skim:
#' `skim()` is an intentionally simple function, with minimal arguments like
#' [`summary()`]. Nonetheless, this package provides two broad approaches to
#' [summary()]. Nonetheless, this package provides two broad approaches to
#' how you can customize `skim()`'s behavior. You can customize the functions
#' that are called to produce summary statistics with [`skim_with()`].
#' that are called to produce summary statistics with [skim_with()].
#'
#' @section Unicode rendering:
#' If the rendered examples show unencoded values such as `<U+2587>` you will
#' need to change your locale to allow proper rendering. Please review the
#' *Using Skimr* vignette for more information
#' (`vignette("Using_skimr", package = "skimr")`).
#'
#' @param .data A tibble, or an object that can be coerced into a tibble.
#' Otherwise, we export `skim_without_charts()` to produce summaries without the
#' spark graphs. These are the source of the unicode dependency.
#'
#' @param data A tibble, or an object that can be coerced into a tibble.
#' @param ... Columns to select for skimming. When none are provided, the
#' default is to skim all columns.
#' @param skim The skimming function to use in `skim_tee()`.
Expand Down Expand Up @@ -71,15 +74,25 @@
#' chickwts %>%
#' skim_tee() %>%
#' dplyr::filter(feed == "sunflower")
#'
#' # Produce a summary without spark graphs
#' iris %>%
#' skim_without_charts()
#' @export
skim <- skim_with()

#' @rdname skim
#' @param data The data frame that is skimmed and returned.
#' @param skim_fun The skim function used.
#' @export
skim_tee <- function(.data, ..., skim_fun = skim) {
skimmed <- skim_fun(.data, ...)
skim_tee <- function(data, ..., skim_fun = skim) {
skimmed <- skim_fun(data, ...)
print(skimmed)
invisible(.data)
invisible(data)
}

#' @rdname skim
#' @export
skim_without_charts <- skim_with(
numeric = sfl(hist = NULL),
ts = sfl(line_graph = NULL)
)
2 changes: 1 addition & 1 deletion R/skim_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @name print
NULL

#' @describeIn print Print a skimmed data frame (`skim_df` from [`skim()`]).
#' @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, ...) {
Expand Down
2 changes: 1 addition & 1 deletion R/summary.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Summary function for skim_df
#'
#' This is a method of the generic function [`summary()`].
#' This is a method of the generic function [summary()].
#'
#' @param object a skim dataframe.
#' @param ... Additional arguments affecting the summary produced. Not used.
Expand Down
2 changes: 2 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ is_windows <- function() {
#' printing a data frame, appearing like this: "<U+2582><U+2585><U+2587>".
#' This longstanding problem originates in the low-level code for printing
#' dataframes.
#'
#' @seealso [skim_without_charts()]
#' @export
fix_windows_histograms <- function() {
message(
Expand Down
5 changes: 4 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ issue in Emacs ESS.
This means that while `skimr` can render the histograms to the console and in
RMarkdown documents, it cannot in other circumstances. This includes:

* rendering a `skimr` data frame within `pander()`
* converting a `skimr` data frame to a vanilla R data frame, but tibbles render
correctly
* in the context of rendering to a pdf using an engine that does not support
Expand All @@ -219,6 +218,10 @@ One workaround for showing these characters in Windows is to set the CTYPE part
of your locale to Chinese/Japanese/Korean with `Sys.setlocale("LC_CTYPE",
"Chinese"). The helper function `fix_windows_histograms()` does this for you.

And last but not least, we provide `skim_without_charts()` as a fallback.
This makes it easy to still get summaries of your data, even if unicode issues
continue.

### Printing spark histograms and line graphs in knitted documents

Spark-bar and spark-line work in the console, but may not work when you knit
Expand Down
Loading

0 comments on commit 2f5c322

Please sign in to comment.