skimr (version 1.0.4)

skim_with: Set or add the summary functions for a particular type of data

Description

While skim is designed around having an opinionated set of defaults, you can use these functions to change the summary statistics that it returns. To do that, provide type you wish to change as an argument to this function, along with a list of named functions that you want to use instead of the defaults.

Usage

skim_with(..., .list = list(), append = TRUE, drop_new = FALSE)

skim_with_defaults()

show_skimmers(which = NULL)

get_skimmers(which = NULL)

Arguments

...

A list of functions, with an argument name that matches a particular data type.

.list

Instead of individual named entries, you can provided a list instead. If most ... arguments and .list is provided, values in .list take precedence.

append

Whether the provided options should be in addition to the defaults already in skim. Default is TRUE.

drop_new

Whether types outside of the defaults should be discarded.

which

A character vector. One or more of the classes whose summary functions you wish to display.

Value

When setting values, invisible(NULL). When looking up values a list. The names of the list match the classes that have assigned summary functions. With show_skimmers(), each entry in the list is a character vector of function names. With get_skimmers(), each entry in the list is itself a list of named functions.

Functions

  • skim_with_defaults: Use the default functions within skim

  • show_skimmers: Access the names of the summary functions for a class.

  • get_skimmers: Pull a list of summary functions for a class.

Details

This function is not pure. It sets values in within the package environment. This is an intentional design choice, with effects similar to setting options in base R. By setting options here for your entire session, you can continue to summarize using skim on its own.

Examples

Run this code
# NOT RUN {
# Use new functions for numeric functions
skim_with(numeric = list(median = median, mad = mad), append = FALSE)
skim(faithful)

# If you want to remove a particular skimmer, set it to NULL
# This removes the inline histogram
skim_with(numeric = list(hist = NULL))
skim(faithful)

# This works with multiple skimmers. Just match names to overwrite
skim_with(numeric = list(iqr = IQR, p25 = NULL, p75 = NULL))
skim(faithful)

# Alternatively, set `append = FALSE` to replace the skimmers of a type.
skim_with(numeric = list(mean = mean, sd = sd), append = FALSE)

# Skimmers are unary functions. Partially apply arguments during assigment.
# For example, you might want to remove NA values.
skim_with(numeric = list(iqr = purrr::partial(IQR, na.rm = TRUE)))

# Or use an rlang-style formula constructor for the function
skim_with(numeric = list(med = ~median(., na.rm = TRUE)))

# Set multiple types of skimmers simultaneously
skim_with(numeric = list(mean = mean), character = list(len = length))

# Or pass the same as a list
my_skimmers <- list(numeric = list(mean = mean),
                    character = list(len = length))
skim_with(.list = my_skimmers)

# Alternatively, use rlang unquoting semantics
skim_with(!!!my_skimmers)

# Go back to defaults
skim_with_defaults()
skim(faithful)

# What are the names of the numeric skimmers?
show_skimmers("numeric")

# I want to create a set of skimmers for the hms class, using the date
# skimmers currently available.
funs <- get_skimmers()
skim_with(hms = funs$date)
# }

Run the code above in your browser using DataCamp Workspace