# NOT RUN {
# Defining default skimming functions for a new class, `my_class`.
# Note that the class argument is required for dynamic reassignment.
get_skimmers.my_class <- function(column) {
sfl(
skim_type = "my_class",
mean,
sd
)
}
# Integer and double columns are both "numeric" and are treated the same
# by default. To switch this behavior in another package, add a method.
get_skimmers.integer <- function(column) {
sfl(
skim_type = "integer",
p50 = ~ stats::quantile(
.,
probs = .50, na.rm = TRUE, names = FALSE, type = 1
)
)
}
x <- mtcars[c("gear", "carb")]
class(x$carb) <- "integer"
skim(x)
# }
# NOT RUN {
# In a package, to revert to the V1 behavior of skimming separately with the
# same functions, assign the numeric `get_skimmers`.
get_skimmers.integer <- skimr::get_skimmers.numeric
# Or, in a local session, use `skim_with` to create a different `skim`.
new_skim <- skim_with(integer = skimr::get_skimmers.numeric())
# To apply a set of skimmers from an old type to a new type
get_skimmers.new_type <- function(column) {
modify_default_skimmers("old_type", new_skim_type = "new_type")
}
# }
Run the code above in your browser using DataLab