Skip to content

Commit

Permalink
Merge pull request #618 from ropensci/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
elinw authored Sep 29, 2020
2 parents 461f9a5 + f2dc1dd commit 22dfec2
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 98 deletions.
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ Authors@R:
person(given = "Kyle",
family = "Butts",
role ="ctb",
email = "[email protected]"))
email = "[email protected]"),
person(given = "Bastian",
family = "Torges",
role ="ctb",
email = "[email protected]"))
Description: A simple to use summary function that can be used with pipes
and displays nicely in the console. The default summary statistics may
be modified by the user as can the default formatting. Support for
Expand Down Expand Up @@ -119,7 +123,7 @@ Imports:
stringr (>= 1.1),
tibble (>= 2.0.0),
tidyr (>= 1.0),
tidyselect (>= 0.2.5),
tidyselect (>= 1.0.0),
withr
Suggests:
covr,
Expand Down
1 change: 1 addition & 0 deletions R/skim.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#' # Use tidyselect
#' skim(iris, Species)
#' skim(iris, starts_with("Sepal"))
#' skim(iris, where(is.numeric))
#'
#' # Skim also works groupwise
#' iris %>%
Expand Down
25 changes: 14 additions & 11 deletions R/skim_with.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ skim_with <- function(...,
data <- as.data.frame(data)
}
stopifnot(inherits(data, "data.frame"))

.vars <- rlang::quos(...)
cols <- names(data)
if (length(.vars) == 0) {
selected <- cols
} else {
selected <- tidyselect::vars_select(cols, !!!.vars)
}

selected <- names(tidyselect::eval_select(rlang::expr(c(...)), data))
if (length(selected) == 0) {
selected <- names(data)
}

grps <- dplyr::groups(data)
if (length(grps) > 0) {
Expand Down Expand Up @@ -321,13 +318,19 @@ skim_by_type <- function(mangled_skimmers, variable_names, data) {
skim_by_type.grouped_df <- function(mangled_skimmers, variable_names, data) {
group_columns <- dplyr::groups(data)
grouped <- dplyr::group_by(data, !!!group_columns)
skimmed <- dplyr::summarize_at(grouped, variable_names, mangled_skimmers$funs)
skimmed <- dplyr::summarize(
grouped,
dplyr::across(variable_names, mangled_skimmers$funs)
)
build_results(skimmed, variable_names, group_columns)
}

#' @export
skim_by_type.data.frame <- function(mangled_skimmers, variable_names, data) {
skimmed <- dplyr::summarize_at(data, variable_names, mangled_skimmers$funs)
skimmed <- dplyr::summarize(
data,
dplyr::across(variable_names, mangled_skimmers$funs)
)
build_results(skimmed, variable_names, NULL)
}

Expand Down Expand Up @@ -358,7 +361,7 @@ reshape_skimmed <- function(column, skimmed, groups) {
out <- dplyr::select(
as.data.frame(skimmed),
!!!groups,
tidyselect::starts_with(delim_name)
tidyselect::starts_with(delim_name, ignore.case = FALSE)
)
set_clean_names(out)
}
Expand Down
1 change: 1 addition & 0 deletions man/skim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-get_skimmers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ context("Get skimmers")

test_that("get_sfl() behaves correctly", {
my_sfl <- get_sfl("numeric")
expect_is(my_sfl, "skimr_function_list")
expect_s3_class(my_sfl, "skimr_function_list")
expect_equal(my_sfl$skim_type, "numeric")
expect_named(my_sfl$funs, c(
"mean", "sd", "p0", "p25", "p50", "p75", "p100", "hist"
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ context("Reshaping a skim_df")
test_that("You can parition a skim_df", {
skimmed <- skim(iris)
input <- partition(skimmed)
expect_is(input, "skim_list")
expect_s3_class(input, "skim_list")
expect_length(input, 2)
expect_named(input, c("factor", "numeric"))
attrs <- attributes(input)
Expand All @@ -20,15 +20,15 @@ test_that("You can parition a skim_df", {
)

# Subtables
expect_is(input$factor, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_s3_class(input$factor, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_n_rows(input$factor, 1)
expect_n_columns(input$factor, 6)
expect_named(input$factor, c(
"skim_variable", "n_missing", "complete_rate", "ordered", "n_unique",
"top_counts"
))

expect_is(input$numeric, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_s3_class(input$numeric, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_n_rows(input$numeric, 4)
expect_n_columns(input$numeric, 11)
expect_named(input$numeric, c(
Expand All @@ -48,7 +48,7 @@ test_that("Partitioning works in a round trip", {
test_that("You can yank a subtable from a skim_df", {
skimmed <- skim(iris)
input <- yank(skimmed, "numeric")
expect_is(input, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_s3_class(input, c("one_skim_df", "tbl_df", "tbl", "data.frame"))
expect_n_rows(input, 4)
expect_n_columns(input, 11)
expect_named(input, c(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-sfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ test_that("Zero-length sfl's supported", {

test_that("The interface for sfl's separates keep and drop functions", {
input <- sfl(mad = mad, hist = NULL, skim_type = "test")
expect_is(input, "skimr_function_list")
expect_s3_class(input, "skimr_function_list")
expect_length(input, 2)
expect_named(input, c("funs", "skim_type"))
expect_identical(input$skim_type, "test")

funs <- input$funs
expect_is(funs, "list")
expect_type(funs, "list")
expect_named(funs, c("mad", "hist"))
})

Expand Down
Loading

0 comments on commit 22dfec2

Please sign in to comment.