Debian Codegraph @

man/skim_with.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/skim_with.R
3 \name{skim_with}
4 \alias{skim_with}
5 \title{Set or add the summary functions for a particular type of data}
6 \usage{
7 skim_with(
8 ...,
9 base = sfl(n_missing = n_missing, complete_rate = complete_rate),
10 append = TRUE
11 )
12 }
13 \arguments{
14 \item{...}{One or more (\code{sfl}) \code{skimmer_function_list} objects, with an
15 argument name that matches a particular data type.}
16
17 \item{base}{An \code{sfl} that sets skimmers for all column types.}
18
19 \item{append}{Whether the provided options should be in addition to the
20 defaults already in \code{skim}. Default is \code{TRUE}.}
21 }
22 \value{
23 A new \code{skim()} function. This is callable. See \code{\link[=skim]{skim()}} for more
24 details.
25 }
26 \description{
27 While skim is designed around having an opinionated set of defaults, you
28 can use this function to change the summary statistics that it returns.
29 }
30 \details{
31 \code{skim_with()} is a closure: a function that returns a new function. This
32 lets you have several skimming functions in a single R session, but it
33 also means that you need to assign the return of \code{skim_with()} before
34 you can use it.
35
36 You assign values within \code{skim_with} by using the \code{\link[=sfl]{sfl()}} helper (\code{skimr}
37 function list). This helper behaves mostly like \code{\link[dplyr:funs]{dplyr::funs()}}, but lets
38 you also identify which skimming functions you want to remove, by setting
39 them to \code{NULL}. Assign an \code{sfl} to each column type that you wish to modify.
40
41 Functions that summarize all data types, and always return the same type
42 of value, can be assigned to the \code{base} argument. The default base skimmers
43 compute the number of missing values \code{\link[=n_missing]{n_missing()}} and the rate of values
44 being complete, i.e. not missing, \code{\link[=complete_rate]{complete_rate()}}.
45
46 When \code{append = TRUE} and local skimmers have names matching the names of
47 entries in the default \code{skim_function_list}, the values in the default list
48 are overwritten. Similarly, if \code{NULL} values are passed within \code{sfl()}, these
49 default skimmers are dropped. Otherwise, if \code{append = FALSE}, only the
50 locally-provided skimming functions are used.
51
52 Note that \code{append} only applies to the \code{typed} skimmers (i.e. non-base).
53 See \code{\link[=get_default_skimmer_names]{get_default_skimmer_names()}} for a list of defaults.
54 }
55 \examples{
56 # Use new functions for numeric functions. If you don't provide a name,
57 # one will be automatically generated.
58 my_skim <- skim_with(numeric = sfl(median, mad), append = FALSE)
59 my_skim(faithful)
60
61 # If you want to remove a particular skimmer, set it to NULL
62 # This removes the inline histogram
63 my_skim <- skim_with(numeric = sfl(hist = NULL))
64 my_skim(faithful)
65
66 # This works with multiple skimmers. Just match names to overwrite
67 my_skim <- skim_with(numeric = sfl(iqr = IQR, p25 = NULL, p75 = NULL))
68 my_skim(faithful)
69
70 # Alternatively, set `append = FALSE` to replace the skimmers of a type.
71 my_skim <- skim_with(numeric = sfl(mean = mean, sd = sd), append = FALSE)
72
73 # Skimmers are unary functions. Partially apply arguments during assigment.
74 # For example, you might want to remove NA values.
75 my_skim <- skim_with(numeric = sfl(iqr = ~ IQR(., na.rm = TRUE)))
76
77 # Set multiple types of skimmers simultaneously.
78 my_skim <- skim_with(numeric = sfl(mean), character = sfl(length))
79
80 # Or pass the same as a list, unquoting the input.
81 my_skimmers <- list(numeric = sfl(mean), character = sfl(length))
82 my_skim <- skim_with(!!!my_skimmers)
83
84 # Use the v1 base skimmers instead.
85 my_skim <- skim_with(base = sfl(
86 missing = n_missing,
87 complete = n_complete,
88 n = length
89 ))
90
91 # Remove the base skimmers entirely
92 my_skim <- skim_with(base = NULL)
93 }