diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index fa7b90ad..770082fe 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,11 +2,12 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [develop, main] + branches: [main, develop] pull_request: - branches: [develop, main] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -18,7 +19,7 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} @@ -29,7 +30,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -47,3 +48,4 @@ jobs: - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/manual-standard-check.yaml b/.github/workflows/manual-standard-check.yaml deleted file mode 100644 index 0cf77353..00000000 --- a/.github/workflows/manual-standard-check.yaml +++ /dev/null @@ -1,78 +0,0 @@ -# A manually-triggered R CMD check. Runs on all R versions and OS's -# and should be used when preparing for a release. -on: workflow_dispatch - -name: manual-standard-check - -jobs: - manual-standard-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - r-version: ${{ matrix.config.r }} - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check \ No newline at end of file diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml deleted file mode 100644 index 62e2fde5..00000000 --- a/.github/workflows/pkgdown.yaml +++ /dev/null @@ -1,47 +0,0 @@ -on: - push: - branches: - - main - -name: pkgdown - -jobs: - pkgdown: - runs-on: macOS-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v2 - - - uses: r-lib/actions/setup-pandoc@v2 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - install.packages("pkgdown", type = "binary") - shell: Rscript {0} - - - name: Install package - run: R CMD INSTALL . - - - name: Deploy package - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 51b996fc..e050312f 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,54 +1,61 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - main + branches: [main, master] pull_request: - branches: - - main -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest env: - RSPM: https://packagemanager.rstudio.com/cran/__linux__/bionic/latest GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 - id: install-r - - - name: Install pak and query dependencies - run: | - install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") - saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds") - shell: Rscript {0} + with: + use-public-rspm: true - - name: Restore R package cache - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - path: | - ${{ env.R_LIBS_USER }}/* - !${{ env.R_LIBS_USER }}/pak - key: ubuntu-18.04-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }} - restore-keys: ubuntu-18.04-${{ steps.install-r.outputs.installed-r-version }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' + extra-packages: any::covr, any::xml2 + needs: coverage + + - name: Test coverage run: | - pak::local_system_requirements(execute = TRUE) - pak::pkg_system_requirements("covr", execute = TRUE) + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + covr::to_cobertura(cov) shell: Rscript {0} - - name: Install dependencies + - uses: codecov/codecov-action@v4 + with: + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() run: | - pak::local_install_dev_deps(upgrade = TRUE) - pak::pkg_install("covr") - shell: Rscript {0} + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 9d302ee0..32fa4227 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -121,7 +121,7 @@ Depends: R (>= 3.1.2) Imports: cli, - dplyr (>= 0.8.0), + dplyr (>= 1.0.0), knitr (>= 1.2), magrittr (>= 1.5), pillar (>= 1.6.4), @@ -133,23 +133,21 @@ Imports: tibble (>= 2.0.0), tidyr (>= 1.0), tidyselect (>= 1.0.0), - vctrs + vctrs (>= 0.5.0) Suggests: - covr, - crayon, data.table, dtplyr, extrafont, haven, lubridate, rmarkdown, - testthat (>= 2.0.0), + testthat (>= 3.0.0), withr VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Collate: 'deprecated.R' 'dplyr.R' @@ -165,3 +163,4 @@ Collate: 'summary.R' 'utils.R' 'vctrs.R' +Config/testthat/edition: 3 diff --git a/R/reshape.R b/R/reshape.R index 88e0b147..be95b6ea 100644 --- a/R/reshape.R +++ b/R/reshape.R @@ -81,10 +81,9 @@ reconcile_skimmers <- function(data, groups, base) { extra_cols <- dplyr::setdiff(all_columns, with_base_columns) if (length(extra_cols) > 0) { grouped <- dplyr::group_by(data, .data$skim_type) - complete_by_type <- dplyr::summarize_at( + complete_by_type <- dplyr::summarise( grouped, - extra_cols, - ~ !all(is.na(.x)) + dplyr::across(tidyselect::all_of(extra_cols), ~ !all(is.na(.x))) ) complete_cols <- purrr::pmap( complete_by_type, @@ -242,12 +241,12 @@ to_long.default <- function(.data, ..., skim_fun = skim) { #' @describeIn to_long Transform a skim_df to a long data frame. #' @export to_long.skim_df <- function(.data, ..., skim_fun = skim) { - tidyr::gather( + .data <- dplyr::mutate(.data, dplyr::across(dplyr::everything(), as.character)) + tidyr::pivot_longer( .data, - key = "stat", - value = "formatted", - na.rm = TRUE, - -"skim_type", - -"skim_variable" + cols = c(-"skim_type", -"skim_variable"), + names_to = "stat", + values_to = "formatted", + values_drop_na = TRUE ) } diff --git a/R/skim.R b/R/skim.R index 06d6a818..950adde9 100644 --- a/R/skim.R +++ b/R/skim.R @@ -73,7 +73,7 @@ #' iris %>% #' skim() %>% #' dplyr::select(numeric.mean) %>% -#' dplyr::top_n(5) +#' dplyr::slice_head(n = 5) #' #' # Which of my columns have missing values? Use the base skimmer n_missing. #' iris %>% diff --git a/R/skim_print.R b/R/skim_print.R index 1ebf5f64..5fde5a48 100644 --- a/R/skim_print.R +++ b/R/skim_print.R @@ -26,7 +26,7 @@ #' #' @inheritParams tibble::print.tbl #' @seealso [tibble::trunc_mat()] For a list of global options for customizing -#' print formatting. [crayon::has_color()] for the variety of issues that +#' print formatting. [cli::num_ansi_colors()] for the variety of issues that #' affect tibble's color support. #' @param include_summary Whether a summary of the data frame should be printed #' @param summary_rule_width Width of Data Summary cli rule, defaults to 40. diff --git a/R/skimr-package.R b/R/skimr-package.R index 74df0771..241224df 100644 --- a/R/skimr-package.R +++ b/R/skimr-package.R @@ -10,16 +10,12 @@ #' provides an API for customization. Users can change both the functions #' dispatched and the way the results are formatted. #' -#' @importFrom rlang .data -#' @name skimr-package -#' @aliases skimr -#' @docType package -NULL +"_PACKAGE" # Imports ----------------------------------------------------------------- -#' @importFrom rlang %||% +#' @importFrom rlang %||% .data #' @importFrom magrittr %>% #' @export diff --git a/README.Rmd b/README.Rmd index 06240715..f70a609c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -8,21 +8,22 @@ align="right" height="139" /> ```{r set-options, echo=FALSE, message=FALSE} library(skimr) -options(tibble.width = Inf) +options(pillar.width = Inf) options(width = 100) ``` + [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/) -[![R build -status](https://github.com/ropensci/skimr/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/skimr/actions?workflow=R-CMD-check) -[![codecov](https://codecov.io/gh/ropensci/skimr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ropensci/skimr) +[![R-CMD-check](https://github.com/ropensci/skimr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/skimr/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/ropensci/skimr/graph/badge.svg)](https://app.codecov.io/gh/ropensci/skimr) [![This is an ROpenSci Peer reviewed package](https://badges.ropensci.org/175_status.svg)](https://github.com/ropensci/software-review/issues/175) [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/skimr)](https://cran.r-project.org/package=skimr) [![cran checks](https://badges.cranchecks.info/worst/skimr.svg)](https://badges.cranchecks.info/worst/skimr.svg) + `skimr` provides a frictionless approach to summary statistics which conforms diff --git a/README.md b/README.md index 6f9b0656..82a1f717 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,20 @@ + + [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/) -[![R build -status](https://github.com/ropensci/skimr/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/skimr/actions?workflow=R-CMD-check) -[![codecov](https://codecov.io/gh/ropensci/skimr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ropensci/skimr) +[![R-CMD-check](https://github.com/ropensci/skimr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/skimr/actions/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/ropensci/skimr/graph/badge.svg)](https://app.codecov.io/gh/ropensci/skimr) [![This is an ROpenSci Peer reviewed package](https://badges.ropensci.org/175_status.svg)](https://github.com/ropensci/software-review/issues/175) [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/skimr)](https://cran.r-project.org/package=skimr) -[![cran checks](https://badges.cranchecks.info/worst/skimr.svg)](https://cran.r-project.org/web/checks/check_results_skimr.html) +[![cran +checks](https://badges.cranchecks.info/worst/skimr.svg)](https://badges.cranchecks.info/worst/skimr.svg) + `skimr` provides a frictionless approach to summary statistics which conforms to the [principle of least @@ -130,7 +134,7 @@ change. ## ── Variable type: character ──────────────────────────────────────────────────────────────────────── ## skim_variable n_missing complete_rate min max empty n_unique whitespace ## 1 name 0 1 3 21 0 87 0 - ## 2 hair_color 5 0.943 4 13 0 12 0 + ## 2 hair_color 5 0.943 4 13 0 11 0 ## 3 skin_color 0 1 3 19 0 31 0 ## 4 eye_color 0 1 3 13 0 15 0 ## 5 sex 4 0.954 4 14 0 4 0 @@ -142,11 +146,11 @@ change. ## skim_variable n_missing complete_rate n_unique min_length max_length ## 1 films 0 1 24 1 7 ## 2 vehicles 0 1 11 0 2 - ## 3 starships 0 1 17 0 5 + ## 3 starships 0 1 16 0 5 ## ## ── Variable type: numeric ────────────────────────────────────────────────────────────────────────── ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - ## 1 height 6 0.931 174. 34.8 66 167 180 191 264 ▁▁▇▅▁ + ## 1 height 6 0.931 175. 34.8 66 167 180 191 264 ▂▁▇▅▁ ## 2 mass 28 0.678 97.3 169. 15 55.6 79 84.5 1358 ▇▁▁▁▁ ## 3 birth_year 44 0.494 87.6 155. 8 35 52 72 896 ▇▁▁▁▁ diff --git a/man/fix_windows_histograms.Rd b/man/fix_windows_histograms.Rd index 66fab42b..0a96bb98 100644 --- a/man/fix_windows_histograms.Rd +++ b/man/fix_windows_histograms.Rd @@ -8,13 +8,13 @@ fix_windows_histograms() } \description{ This functions changes your session's locale to address issues with printing -histograms on Windows. +histograms on Windows on versions of R below 4.2.1. } \details{ There are known issues with printing the spark-histogram characters when printing a data frame, appearing like this: "". This longstanding problem originates in the low-level code for printing -dataframes. +dataframes. This was addressed in R version 4.2.1. } \seealso{ \code{\link[=skim_without_charts]{skim_without_charts()}} diff --git a/man/print.Rd b/man/print.Rd index f89681db..da286e7b 100644 --- a/man/print.Rd +++ b/man/print.Rd @@ -35,7 +35,7 @@ means use the \code{width} \link[pillar:pillar_options]{option}.} \item{summary_rule_width}{Width of Data Summary cli rule, defaults to 40.} -\item{...}{Passed on to \code{\link[=tbl_format_setup]{tbl_format_setup()}}.} +\item{...}{Passed on to \code{\link[pillar:tbl_format_setup]{pillar::tbl_format_setup()}}.} \item{.summary_rule_width}{the width for the main rule above the summary.} } @@ -81,6 +81,6 @@ You can control the width rule line for the printed subtables with an option: \seealso{ \code{\link[tibble:trunc_mat]{tibble::trunc_mat()}} For a list of global options for customizing -print formatting. \code{\link[crayon:has_color]{crayon::has_color()}} for the variety of issues that +print formatting. \code{\link[cli:num_ansi_colors]{cli::num_ansi_colors()}} for the variety of issues that affect tibble's color support. } diff --git a/man/skim.Rd b/man/skim.Rd index f73600f1..6e6ff303 100644 --- a/man/skim.Rd +++ b/man/skim.Rd @@ -100,7 +100,7 @@ iris \%>\% iris \%>\% skim() \%>\% dplyr::select(numeric.mean) \%>\% - dplyr::top_n(5) + dplyr::slice_head(n = 5) # Which of my columns have missing values? Use the base skimmer n_missing. iris \%>\% diff --git a/man/skimr-package.Rd b/man/skimr-package.Rd index 73337290..ee151c8d 100644 --- a/man/skimr-package.Rd +++ b/man/skimr-package.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/skimr-package.R \docType{package} \name{skimr-package} -\alias{skimr-package} \alias{skimr} +\alias{skimr-package} \title{Skim a data frame} \description{ This package provides an alternative to the default summary functions @@ -17,3 +17,49 @@ that are generated for a variety of different data types. It is also provides an API for customization. Users can change both the functions dispatched and the way the results are formatted. } +\seealso{ +Useful links: +\itemize{ + \item \url{https://docs.ropensci.org/skimr/ (website)} + \item \url{https://github.com/ropensci/skimr/} + \item Report bugs at \url{https://github.com/ropensci/skimr/issues} +} + +} +\author{ +\strong{Maintainer}: Elin Waring \email{elin.waring@gmail.com} + +Authors: +\itemize{ + \item Michael Quinn \email{msquinn@google.com} + \item Amelia McNamara \email{amcnamara@smith.edu} + \item Eduardo Arino de la Rubia \email{earino@gmail.com} + \item Hao Zhu \email{haozhu233@gmail.com} + \item Shannon Ellis \email{sellis18@jhmi.edu} +} + +Other contributors: +\itemize{ + \item Julia Lowndes \email{lowndes@nceas.ucsb.edu} [contributor] + \item Hope McLeod \email{hmgit2@gmail.com} [contributor] + \item Hadley Wickham \email{hadley@rstudio.com} [contributor] + \item Kirill Müller \email{krlmlr+r@mailbox.org} [contributor] + \item RStudio, Inc. (Spark functions) [copyright holder] + \item Connor Kirkpatrick \email{hello@connorkirkpatrick.com} [contributor] + \item Scott Brenstuhl \email{brenstsr@miamioh.edu} [contributor] + \item Patrick Schratz \email{patrick.schratz@gmail.com} [contributor] + \item lbusett \email{lbusett@gmail.com} [contributor] + \item Mikko Korpela \email{mvkorpel@iki.fi} [contributor] + \item Jennifer Thompson \email{thompson.jennifer@gmail.com} [contributor] + \item Harris McGehee \email{mcgehee.harris@gmail.com} [contributor] + \item Mark Roepke \email{mroepke5@gmail.com} [contributor] + \item Patrick Kennedy \email{pkqstr@protonmail.com} [contributor] + \item Daniel Possenriede \email{possenriede@gmail.com} [contributor] + \item David Zimmermann \email{david_j_zimmermann@hotmail.com} [contributor] + \item Kyle Butts \email{buttskyle96@gmail.com} [contributor] + \item Bastian Torges \email{bastian.torges@gmail.com} [contributor] + \item Rick Saporta \email{Rick@TheFarmersDog.com} [contributor] + \item Henry Morgan Stewart \email{henry.morganstewart@gmail.com} [contributor] +} + +} diff --git a/man/skimr-vctrs.Rd b/man/skimr-vctrs.Rd index e01ce9e3..121d44da 100644 --- a/man/skimr-vctrs.Rd +++ b/man/skimr-vctrs.Rd @@ -31,7 +31,7 @@ why this is important and how these functions work, see: \details{ \verb{vec_ptype2.*} handles finding common prototypes between \code{skim_df} and similar objects. \verb{vec_cast.*} handles casting between objects. Note that -as of \verb{dplyr 1.0.2}, \code{\link[dplyr:bind]{dplyr::bind_rows()}} does not full support combining +as of \verb{dplyr 1.0.2}, \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} does not full support combining attributes and \code{\link[vctrs:vec_bind]{vctrs::vec_rbind()}} is preferred instead. } \keyword{internal} diff --git a/tests/testthat.R b/tests/testthat.R index e505969a..0c220f56 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(skimr) diff --git a/tests/testthat/_snaps/data-table.md b/tests/testthat/_snaps/data-table.md new file mode 100644 index 00000000..99322c17 --- /dev/null +++ b/tests/testthat/_snaps/data-table.md @@ -0,0 +1,143 @@ +# skim of a simple data.table produces output as expected + + Code + skimmed_DT_letters + Output + -- Data Summary ------------------------ + Values + Name DT_letters + Number of rows 26 + Number of columns 1 + Key NULL + _______________________ + Column type frequency: + character 1 + ________________________ + Group variables None + + -- Variable type: character --------------------------------------------------------------- + skim_variable n_missing complete_rate min max empty n_unique whitespace + 1 abc 0 1 1 1 0 26 0 + +# skim of data.table produces output as expected + + Code + skim(DT_factors) + Output + -- Data Summary ------------------------ + Values + Name DT_factors + Number of rows 26 + Number of columns 3 + Key NULL + _______________________ + Column type frequency: + character 1 + factor 1 + numeric 1 + ________________________ + Group variables None + + -- Variable type: character --------------------------------------------------------------- + skim_variable n_missing complete_rate min max empty n_unique whitespace + 1 abc 0 1 1 1 0 26 0 + + -- Variable type: factor ------------------------------------------------------------------ + skim_variable n_missing complete_rate ordered n_unique top_counts + 1 grps 0 1 FALSE 2 AA: 18, BB: 8 + + -- Variable type: numeric ----------------------------------------------------------------- + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + +--- + + Code + skim(DT_factors) + Output + -- Data Summary ------------------------ + Values + Name DT_factors + Number of rows 26 + Number of columns 3 + Key abc, grps + _______________________ + Column type frequency: + character 1 + factor 1 + numeric 1 + ________________________ + Group variables None + + -- Variable type: character --------------------------------------------------------------- + skim_variable n_missing complete_rate min max empty n_unique whitespace + 1 abc 0 1 1 1 0 26 0 + + -- Variable type: factor ------------------------------------------------------------------ + skim_variable n_missing complete_rate ordered n_unique top_counts + 1 grps 0 1 FALSE 2 AA: 18, BB: 8 + + -- Variable type: numeric ----------------------------------------------------------------- + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + +--- + + Code + skim(DF_factors) + Output + -- Data Summary ------------------------ + Values + Name DF_factors + Number of rows 26 + Number of columns 3 + _______________________ + Column type frequency: + character 1 + factor 1 + numeric 1 + ________________________ + Group variables None + + -- Variable type: character --------------------------------------------------------------- + skim_variable n_missing complete_rate min max empty n_unique whitespace + 1 abc 0 1 1 1 0 26 0 + + -- Variable type: factor ------------------------------------------------------------------ + skim_variable n_missing complete_rate ordered n_unique top_counts + 1 grps 0 1 FALSE 2 AA: 18, BB: 8 + + -- Variable type: numeric ----------------------------------------------------------------- + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + +--- + + Code + skim(tibble_factors) + Output + -- Data Summary ------------------------ + Values + Name tibble_factors + Number of rows 26 + Number of columns 3 + _______________________ + Column type frequency: + character 1 + factor 1 + numeric 1 + ________________________ + Group variables None + + -- Variable type: character --------------------------------------------------------------- + skim_variable n_missing complete_rate min max empty n_unique whitespace + 1 abc 0 1 1 1 0 26 0 + + -- Variable type: factor ------------------------------------------------------------------ + skim_variable n_missing complete_rate ordered n_unique top_counts + 1 grps 0 1 FALSE 2 AA: 18, BB: 8 + + -- Variable type: numeric ----------------------------------------------------------------- + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ + diff --git a/tests/testthat/_snaps/dplyr.md b/tests/testthat/_snaps/dplyr.md new file mode 100644 index 00000000..b479cd95 --- /dev/null +++ b/tests/testthat/_snaps/dplyr.md @@ -0,0 +1,153 @@ +# dplyr::filter works as expected + + Code + dplyr::filter(skimmed_iris, skim_type == "numeric") + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + numeric 4 + ________________________ + Group variables None + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + Code + dplyr::filter(skimmed_iris, skim_type == "no_type") + Output + # A tibble: 0 x 15 + # i 15 variables: skim_type , skim_variable , n_missing , + # complete_rate , factor.ordered , factor.n_unique , + # factor.top_counts , numeric.mean , numeric.sd , + # numeric.p0 , numeric.p25 , numeric.p50 , numeric.p75 , + # numeric.p100 , numeric.hist + +# dplyr::select works as expected + + Code + with_type + Output + # A tibble: 5 x 2 + skim_type skim_variable + + 1 factor Species + 2 numeric Sepal.Length + 3 numeric Sepal.Width + 4 numeric Petal.Length + 5 numeric Petal.Width + +--- + + Code + without_type + Output + # A tibble: 5 x 1 + numeric.mean + + 1 NA + 2 5.84 + 3 3.06 + 4 3.76 + 5 1.20 + +# dplyr::mutate works as expected + + Code + input + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + mean2 + 1 34.1 + 2 9.35 + 3 14.1 + 4 1.44 + +# dplyr::slice works as expected + + Code + input + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 2 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + +# dplyr::arrange works as expected + + Code + dplyr::arrange(skimmed_iris, desc(numeric.mean)) + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 3 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + diff --git a/tests/testthat/_snaps/skim_print.md b/tests/testthat/_snaps/skim_print.md new file mode 100644 index 00000000..186cb1ea --- /dev/null +++ b/tests/testthat/_snaps/skim_print.md @@ -0,0 +1,393 @@ +# Skim prints a header for the entire output and each type + + Code + input <- skim(iris) + input + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + Code + input$numeric.hist <- NULL + input + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 + +# Skim prints a special header for grouped data frames + + Code + skim(dplyr::group_by(iris, Species)) + Output + -- Data Summary ------------------------ + Values + Name dplyr::group_by(iris, Spe... + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + numeric 4 + ________________________ + Group variables Species + + -- Variable type: numeric ------------------------------------------------------ + skim_variable Species n_missing complete_rate mean sd p0 p25 p50 + 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 + 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 + 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 + 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 + 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 + 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 + 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 + 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 + 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 + 10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 + 11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 + 12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 + p75 p100 hist + 1 5.2 5.8 ▃▃▇▅▁ + 2 6.3 7 ▂▇▆▃▃ + 3 6.9 7.9 ▁▃▇▃▂ + 4 3.68 4.4 ▁▃▇▅▂ + 5 3 3.4 ▁▅▆▇▂ + 6 3.18 3.8 ▂▆▇▅▁ + 7 1.58 1.9 ▁▃▇▃▁ + 8 4.6 5.1 ▂▂▇▇▆ + 9 5.88 6.9 ▃▇▇▃▂ + 10 0.3 0.6 ▇▂▂▁▁ + 11 1.5 1.8 ▅▇▃▆▁ + 12 2.3 2.5 ▂▇▆▅▇ + +# Skim lists print as expected + + Code + partition(skimmed) + Output + $factor + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique top_counts + 1 Species 0 1 FALSE 3 set: 50, ver: 50, vir:~ + + $numeric + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + + +# knit_print produces expected results + + Code + cat(input) + Output + + Table: Data summary + + | | | + |:------------------------|:----| + |Name |iris | + |Number of rows |150 | + |Number of columns |5 | + |_______________________ | | + |Column type frequency: | | + |factor |1 | + |numeric |4 | + |________________________ | | + |Group variables |None | + + + **Variable type: factor** + + |skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | + |:-------------|---------:|-------------:|:-------|--------:|:-------------------------| + |Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | + + + **Variable type: numeric** + + |skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | + |:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| + |Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | + |Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | + |Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | + |Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | + + +# knit_print works with skim summaries + + Code + cat(knitr::knit_print(summarized)) + Output + Table: Data summary + + | | | + |:------------------------|:----| + |Name |iris | + |Number of rows |150 | + |Number of columns |5 | + |_______________________ | | + |Column type frequency: | | + |factor |1 | + |numeric |4 | + |________________________ | | + |Group variables |None | + +# knit_print appropriately falls back to tibble printing + + Code + input <- knitr::knit_print(reduced) + Output + # A tibble: 5 x 2 + skim_variable numeric.mean + + 1 Species NA + 2 Sepal.Length 5.84 + 3 Sepal.Width 3.06 + 4 Petal.Length 3.76 + 5 Petal.Width 1.20 + +# Summaries can be suppressed within knitr + + Code + cat(knitr::knit_print(skimmed, options = options)) + Output + + + + **Variable type: factor** + + |skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | + |:-------------|---------:|-------------:|:-------|--------:|:-------------------------| + |Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | + + + **Variable type: numeric** + + |skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | + |:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| + |Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | + |Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | + |Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | + |Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | + + +# Skim lists have a separate knit_print method + + Code + cat(knit_print(skim_list)) + Output + + + + **Variable type: factor** + + |skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | + |:-------------|---------:|-------------:|:-------|--------:|:-------------------------| + |Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | + + + **Variable type: numeric** + + |skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | + |:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| + |Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | + |Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | + |Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | + |Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | + + +# You can yank a type from a skim_df and call knit_print + + Code + cat(knit_print(skim_one)) + Output + + + **Variable type: factor** + + |skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | + |:-------------|---------:|-------------:|:-------|--------:|:-------------------------| + |Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | + + + +# Skim falls back to tibble::print.tbl() appropriately + + Code + input <- skim(iris) + dplyr::select(input, numeric.mean) + Output + # A tibble: 5 x 1 + numeric.mean + + 1 NA + 2 5.84 + 3 3.06 + 4 3.76 + 5 1.20 + +# Print focused objects appropriately + + Code + focus(skimmed, n_missing) + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing + 1 Species 0 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing + 1 Sepal.Length 0 + 2 Sepal.Width 0 + 3 Petal.Length 0 + 4 Petal.Width 0 + +# Support for smaller consoles can be set with the width option + + Code + skim(iris) + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + +# Table header width can be controlled by an option + + Code + skimmed + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + +# skimr creates appropriate output for Jupyter + + Code + skimmed + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ + 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ + diff --git a/tests/testthat/_snaps/skim_tee.md b/tests/testthat/_snaps/skim_tee.md new file mode 100644 index 00000000..99b320ad --- /dev/null +++ b/tests/testthat/_snaps/skim_tee.md @@ -0,0 +1,96 @@ +# Using skim_tee prints returns the object + + Code + skim_object <- skim_tee(chickwts) + Output + -- Data Summary ------------------------ + Values + Name data + Number of rows 71 + Number of columns 2 + _______________________ + Column type frequency: + factor 1 + numeric 1 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 feed 0 1 FALSE 6 + top_counts + 1 soy: 14, cas: 12, lin: 12, sun: 12 + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 weight 0 1 261. 78.1 108 204. 258 324. 423 ▆▆▇▇▃ + +# skim_tee prints only selected columns, but returns full object + + Code + obj <- skim_tee(iris, Species) + Output + -- Data Summary ------------------------ + Values + Name data + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + ________________________ + Group variables None + + -- Variable type: factor ------------------------------------------------------- + skim_variable n_missing complete_rate ordered n_unique + 1 Species 0 1 FALSE 3 + top_counts + 1 set: 50, ver: 50, vir: 50 + +# skim_tee supports dplyr helpers + + Code + obj <- skim_tee(iris, starts_with("Sepal")) + Output + -- Data Summary ------------------------ + Values + Name data + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + numeric 2 + ________________________ + Group variables None + + -- Variable type: numeric ------------------------------------------------------ + skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist + 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ + 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ + +# Skim_tee works with groups + + Code + obj <- skim_tee(iris_grouped, Sepal.Length, skim_fun = my_skim) + Output + -- Data Summary ------------------------ + Values + Name data + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + numeric 1 + ________________________ + Group variables Species + + -- Variable type: numeric ------------------------------------------------------ + skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 + 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 + 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 + 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 + p100 + 1 5.8 + 2 7 + 3 7.9 + diff --git a/tests/testthat/_snaps/summary.md b/tests/testthat/_snaps/summary.md new file mode 100644 index 00000000..b5ccdcf6 --- /dev/null +++ b/tests/testthat/_snaps/summary.md @@ -0,0 +1,34 @@ +# The summary print method prints the correct object + + Code + skim_summary_input + Output + -- Data Summary ------------------------ + Values + Name iris + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + +# The summary print method prints the correct object when piped + + Code + summary_input + Output + -- Data Summary ------------------------ + Values + Name Piped data + Number of rows 150 + Number of columns 5 + _______________________ + Column type frequency: + factor 1 + numeric 4 + ________________________ + Group variables None + diff --git a/tests/testthat/data.table/summary_DF_factors.txt b/tests/testthat/data.table/summary_DF_factors.txt deleted file mode 100644 index a949786f..00000000 --- a/tests/testthat/data.table/summary_DF_factors.txt +++ /dev/null @@ -1,24 +0,0 @@ --- Data Summary ------------------------ - Values -Name DF_factors -Number of rows 26 -Number of columns 3 -_______________________ -Column type frequency: - character 1 - factor 1 - numeric 1 -________________________ -Group variables None - --- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 grps 0 1 FALSE 2 AA: 18, BB: 8 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_factors.txt b/tests/testthat/data.table/summary_DT_factors.txt deleted file mode 100644 index 016d107b..00000000 --- a/tests/testthat/data.table/summary_DT_factors.txt +++ /dev/null @@ -1,25 +0,0 @@ --- Data Summary ------------------------ - Values -Name DT_factors -Number of rows 26 -Number of columns 3 -Key abc, grps -_______________________ -Column type frequency: - character 1 - factor 1 - numeric 1 -________________________ -Group variables None - --- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 grps 0 1 FALSE 2 AA: 18, BB: 8 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_factors_no_key.txt b/tests/testthat/data.table/summary_DT_factors_no_key.txt deleted file mode 100644 index a9f68584..00000000 --- a/tests/testthat/data.table/summary_DT_factors_no_key.txt +++ /dev/null @@ -1,25 +0,0 @@ --- Data Summary ------------------------ - Values -Name DT_factors -Number of rows 26 -Number of columns 3 -Key NULL -_______________________ -Column type frequency: - character 1 - factor 1 - numeric 1 -________________________ -Group variables None - --- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 grps 0 1 FALSE 2 AA: 18, BB: 8 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/data.table/summary_DT_letters.txt b/tests/testthat/data.table/summary_DT_letters.txt deleted file mode 100644 index 94461766..00000000 --- a/tests/testthat/data.table/summary_DT_letters.txt +++ /dev/null @@ -1,15 +0,0 @@ --- Data Summary ------------------------ - Values -Name DT_letters -Number of rows 26 -Number of columns 1 -Key NULL -_______________________ -Column type frequency: - character 1 -________________________ -Group variables None - --- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 diff --git a/tests/testthat/data.table/summary_tibble_factors.txt b/tests/testthat/data.table/summary_tibble_factors.txt deleted file mode 100644 index 91d8d1fc..00000000 --- a/tests/testthat/data.table/summary_tibble_factors.txt +++ /dev/null @@ -1,24 +0,0 @@ --- Data Summary ------------------------ - Values -Name tibble_factors -Number of rows 26 -Number of columns 3 -_______________________ -Column type frequency: - character 1 - factor 1 - numeric 1 -________________________ -Group variables None - --- Variable type: character ------------------------------------------------------------------------ - skim_variable n_missing complete_rate min max empty n_unique whitespace -1 abc 0 1 1 1 0 26 0 - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 grps 0 1 FALSE 2 AA: 18, BB: 8 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 values 0 1 0.0121 0.937 -2.21 -0.335 -0.0306 0.742 1.36 ▂▂▃▇▆ diff --git a/tests/testthat/dplyr/arrange.txt b/tests/testthat/dplyr/arrange.txt deleted file mode 100644 index 542a5552..00000000 --- a/tests/testthat/dplyr/arrange.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -3 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/dplyr/filter-no-skim.txt b/tests/testthat/dplyr/filter-no-skim.txt deleted file mode 100644 index dce473a4..00000000 --- a/tests/testthat/dplyr/filter-no-skim.txt +++ /dev/null @@ -1,5 +0,0 @@ -# A tibble: 0 x 15 -# i 15 variables: skim_type , skim_variable , n_missing , complete_rate , -# factor.ordered , factor.n_unique , factor.top_counts , numeric.mean , -# numeric.sd , numeric.p0 , numeric.p25 , numeric.p50 , numeric.p75 , -# numeric.p100 , numeric.hist diff --git a/tests/testthat/dplyr/filter-skim.txt b/tests/testthat/dplyr/filter-skim.txt deleted file mode 100644 index 66ccfcf1..00000000 --- a/tests/testthat/dplyr/filter-skim.txt +++ /dev/null @@ -1,17 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - numeric 4 -________________________ -Group variables None - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/dplyr/mutate-skim.txt b/tests/testthat/dplyr/mutate-skim.txt deleted file mode 100644 index b8b34668..00000000 --- a/tests/testthat/dplyr/mutate-skim.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist mean2 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ 34.1 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ 9.35 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ 14.1 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ 1.44 diff --git a/tests/testthat/dplyr/select-no-skim.txt b/tests/testthat/dplyr/select-no-skim.txt deleted file mode 100644 index 899ce1b4..00000000 --- a/tests/testthat/dplyr/select-no-skim.txt +++ /dev/null @@ -1,8 +0,0 @@ -# A tibble: 5 x 1 - numeric.mean - -1 NA -2 5.84 -3 3.06 -4 3.76 -5 1.20 diff --git a/tests/testthat/dplyr/select-skim.txt b/tests/testthat/dplyr/select-skim.txt deleted file mode 100644 index 6431bf6f..00000000 --- a/tests/testthat/dplyr/select-skim.txt +++ /dev/null @@ -1,8 +0,0 @@ -# A tibble: 5 x 2 - skim_type skim_variable - -1 factor Species -2 numeric Sepal.Length -3 numeric Sepal.Width -4 numeric Petal.Length -5 numeric Petal.Width diff --git a/tests/testthat/dplyr/slice.txt b/tests/testthat/dplyr/slice.txt deleted file mode 100644 index 298a3bd8..00000000 --- a/tests/testthat/dplyr/slice.txt +++ /dev/null @@ -1,20 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 2 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ diff --git a/tests/testthat/helper-expectations.R b/tests/testthat/helper-expectations.R index 3e2fb690..29ace079 100644 --- a/tests/testthat/helper-expectations.R +++ b/tests/testthat/helper-expectations.R @@ -27,71 +27,3 @@ expect_NA <- function(object) { testthat::expect(is.na(act$val), sprintf("%s is not NA", act$lab)) invisible(act$val) } - -expect_print_matches_file <- function(object, - filename, - skip_on_cran = getOption( - "skimr_skip_on_cran", - TRUE - ), - width = 100, - update = getOption( - "skimr_update_print", - FALSE - ), - skimr_table_header_width = NULL, - ...) { - if (skip_on_cran) testthat::skip_on_cran() - withr::with_options(list( - crayon.enabled = FALSE, - width = width, - skimr_table_header_width = skimr_table_header_width - ), { - testthat::expect_known_output( - print(object, ...), - filename, - update = update, - width = width - ) - }) -} - -expect_matches_file <- function(object, - file, - update = getOption( - "skimr_update_print", - FALSE - ), - skip_on_cran = getOption( - "skimr_skip_on_cran", - TRUE - ), - width = 100, - ...) { - if (skip_on_cran) testthat::skip_on_cran() - withr::local_options(list(crayon.enabled = FALSE, width = width)) - act <- testthat::quasi_label(rlang::enquo(object), NULL) - - if (!file.exists(file)) { - warning("Creating reference value", call. = FALSE) - writeLines(object, file) - testthat::succeed() - } else { - ref_val <- paste0(readLines(file), collapse = "\n") - comp <- testthat::compare(as.character(act$val), ref_val, ...) - if (update && !comp$equal) { - writeLines(act$val, file) - } - - testthat::expect( - comp$equal, - sprintf( - "%s has changed from known value recorded in %s.\n%s", - act$lab, encodeString(file, quote = "'"), comp$message - ), - info = NULL - ) - } - - invisible(act$value) -} diff --git a/tests/testthat/print/default.txt b/tests/testthat/print/default.txt deleted file mode 100644 index bd422226..00000000 --- a/tests/testthat/print/default.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/fallback.txt b/tests/testthat/print/fallback.txt deleted file mode 100644 index 899ce1b4..00000000 --- a/tests/testthat/print/fallback.txt +++ /dev/null @@ -1,8 +0,0 @@ -# A tibble: 5 x 1 - numeric.mean - -1 NA -2 5.84 -3 3.06 -4 3.76 -5 1.20 diff --git a/tests/testthat/print/focus.txt b/tests/testthat/print/focus.txt deleted file mode 100644 index 8ea62b92..00000000 --- a/tests/testthat/print/focus.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing -1 Species 0 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing -1 Sepal.Length 0 -2 Sepal.Width 0 -3 Petal.Length 0 -4 Petal.Width 0 diff --git a/tests/testthat/print/groups.txt b/tests/testthat/print/groups.txt deleted file mode 100644 index daec8fd2..00000000 --- a/tests/testthat/print/groups.txt +++ /dev/null @@ -1,25 +0,0 @@ --- Data Summary ------------------------ - Values -Name dplyr::group_by(iris, Spe... -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - numeric 4 -________________________ -Group variables Species - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist - 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 5.8 ▃▃▇▅▁ - 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 7 ▂▇▆▃▃ - 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 7.9 ▁▃▇▃▂ - 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2 3.4 3.68 4.4 ▁▃▇▅▂ - 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52 2.8 3 3.4 ▁▅▆▇▂ - 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8 3 3.18 3.8 ▂▆▇▅▁ - 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4 1.5 1.58 1.9 ▁▃▇▃▁ - 8 Petal.Length versicolor 0 1 4.26 0.470 3 4 4.35 4.6 5.1 ▂▂▇▇▆ - 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1 5.55 5.88 6.9 ▃▇▇▃▂ -10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2 0.2 0.3 0.6 ▇▂▂▁▁ -11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2 1.3 1.5 1.8 ▅▇▃▆▁ -12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8 2 2.3 2.5 ▂▇▆▅▇ diff --git a/tests/testthat/print/knit_print-fallback.txt b/tests/testthat/print/knit_print-fallback.txt deleted file mode 100644 index 718b29e4..00000000 --- a/tests/testthat/print/knit_print-fallback.txt +++ /dev/null @@ -1,8 +0,0 @@ -# A tibble: 5 x 2 - skim_variable numeric.mean - -1 Species NA -2 Sepal.Length 5.84 -3 Sepal.Width 3.06 -4 Petal.Length 3.76 -5 Petal.Width 1.20 diff --git a/tests/testthat/print/knit_print-skim_list.txt b/tests/testthat/print/knit_print-skim_list.txt deleted file mode 100644 index ec206092..00000000 --- a/tests/testthat/print/knit_print-skim_list.txt +++ /dev/null @@ -1,20 +0,0 @@ - - - -**Variable type: factor** - -|skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | -|:-------------|---------:|-------------:|:-------|--------:|:-------------------------| -|Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | - - -**Variable type: numeric** - -|skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | -|:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| -|Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | -|Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | -|Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | -|Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | - - diff --git a/tests/testthat/print/knit_print-summary.txt b/tests/testthat/print/knit_print-summary.txt deleted file mode 100644 index b86b9271..00000000 --- a/tests/testthat/print/knit_print-summary.txt +++ /dev/null @@ -1,13 +0,0 @@ -Table: Data summary - -| | | -|:------------------------|:----| -|Name |iris | -|Number of rows |150 | -|Number of columns |5 | -|_______________________ | | -|Column type frequency: | | -|factor |1 | -|numeric |4 | -|________________________ | | -|Group variables |None | diff --git a/tests/testthat/print/knit_print-suppressed.txt b/tests/testthat/print/knit_print-suppressed.txt deleted file mode 100644 index ec206092..00000000 --- a/tests/testthat/print/knit_print-suppressed.txt +++ /dev/null @@ -1,20 +0,0 @@ - - - -**Variable type: factor** - -|skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | -|:-------------|---------:|-------------:|:-------|--------:|:-------------------------| -|Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | - - -**Variable type: numeric** - -|skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | -|:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| -|Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | -|Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | -|Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | -|Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | - - diff --git a/tests/testthat/print/knit_print-yank.txt b/tests/testthat/print/knit_print-yank.txt deleted file mode 100644 index 813d3fe4..00000000 --- a/tests/testthat/print/knit_print-yank.txt +++ /dev/null @@ -1,10 +0,0 @@ - - -**Variable type: factor** - -|skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | -|:-------------|---------:|-------------:|:-------|--------:|:-------------------------| -|Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | - - - diff --git a/tests/testthat/print/knit_print.txt b/tests/testthat/print/knit_print.txt deleted file mode 100644 index 41f38251..00000000 --- a/tests/testthat/print/knit_print.txt +++ /dev/null @@ -1,33 +0,0 @@ - -Table: Data summary - -| | | -|:------------------------|:----| -|Name |iris | -|Number of rows |150 | -|Number of columns |5 | -|_______________________ | | -|Column type frequency: | | -|factor |1 | -|numeric |4 | -|________________________ | | -|Group variables |None | - - -**Variable type: factor** - -|skim_variable | n_missing| complete_rate|ordered | n_unique|top_counts | -|:-------------|---------:|-------------:|:-------|--------:|:-------------------------| -|Species | 0| 1|FALSE | 3|set: 50, ver: 50, vir: 50 | - - -**Variable type: numeric** - -|skim_variable | n_missing| complete_rate| mean| sd| p0| p25| p50| p75| p100|hist | -|:-------------|---------:|-------------:|----:|----:|---:|---:|----:|---:|----:|:-----| -|Sepal.Length | 0| 1| 5.84| 0.83| 4.3| 5.1| 5.80| 6.4| 7.9|▆▇▇▅▂ | -|Sepal.Width | 0| 1| 3.06| 0.44| 2.0| 2.8| 3.00| 3.3| 4.4|▁▆▇▂▁ | -|Petal.Length | 0| 1| 3.76| 1.77| 1.0| 1.6| 4.35| 5.1| 6.9|▇▁▆▇▂ | -|Petal.Width | 0| 1| 1.20| 0.76| 0.1| 0.3| 1.30| 1.8| 2.5|▇▁▇▅▃ | - - diff --git a/tests/testthat/print/list.txt b/tests/testthat/print/list.txt deleted file mode 100644 index f30eae92..00000000 --- a/tests/testthat/print/list.txt +++ /dev/null @@ -1,15 +0,0 @@ -$factor - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - -$numeric - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ - diff --git a/tests/testthat/print/narrow-header.txt b/tests/testthat/print/narrow-header.txt deleted file mode 100644 index a44a715b..00000000 --- a/tests/testthat/print/narrow-header.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor ------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric ------------------------ - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/no-hist.txt b/tests/testthat/print/no-hist.txt deleted file mode 100644 index e78eceb4..00000000 --- a/tests/testthat/print/no-hist.txt +++ /dev/null @@ -1,22 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor --------------------------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique top_counts -1 Species 0 1 FALSE 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric -------------------------------------------------------------------------- - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 diff --git a/tests/testthat/print/repr.txt b/tests/testthat/print/repr.txt deleted file mode 100644 index d5960f2c..00000000 --- a/tests/testthat/print/repr.txt +++ /dev/null @@ -1,24 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor ------------------------------------------------------- - skim_variable n_missing complete_rate ordered n_unique -1 Species 0 1 FALSE 3 - top_counts -1 set: 50, ver: 50, vir: 50 - --- Variable type: numeric ------------------------------------------------------ - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/smaller.txt b/tests/testthat/print/smaller.txt deleted file mode 100644 index 633580d8..00000000 --- a/tests/testthat/print/smaller.txt +++ /dev/null @@ -1,29 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor ------------------------- - skim_variable n_missing complete_rate ordered -1 Species 0 1 FALSE - n_unique top_counts -1 3 set: 50, ver: 50, vir: 50 - --- Variable type: numeric ------------------------ - skim_variable n_missing complete_rate mean sd -1 Sepal.Length 0 1 5.84 0.828 -2 Sepal.Width 0 1 3.06 0.436 -3 Petal.Length 0 1 3.76 1.77 -4 Petal.Width 0 1 1.20 0.762 - p0 p25 p50 p75 p100 hist -1 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 2 2.8 3 3.3 4.4 ▁▆▇▂▁ -3 1 1.6 4.35 5.1 6.9 ▇▁▆▇▂ -4 0.1 0.3 1.3 1.8 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/strip-opt.txt b/tests/testthat/print/strip-opt.txt deleted file mode 100644 index 214bec43..00000000 --- a/tests/testthat/print/strip-opt.txt +++ /dev/null @@ -1,35 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor ------------------------------------------------------- -# A tibble: 1 x 6 - skim_variable n_missing complete_rate ordered n_unique -* -1 Species 0 1 FALSE 3 - top_counts -* -1 set: 50, ver: 50, vir: 50 - --- Variable type: numeric ------------------------------------------------------ -# A tibble: 4 x 11 - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 -* -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 - p100 hist -* -1 7.9 ▆▇▇▅▂ -2 4.4 ▁▆▇▂▁ -3 6.9 ▇▁▆▇▂ -4 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/print/strip.txt b/tests/testthat/print/strip.txt deleted file mode 100644 index 214bec43..00000000 --- a/tests/testthat/print/strip.txt +++ /dev/null @@ -1,35 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None - --- Variable type: factor ------------------------------------------------------- -# A tibble: 1 x 6 - skim_variable n_missing complete_rate ordered n_unique -* -1 Species 0 1 FALSE 3 - top_counts -* -1 set: 50, ver: 50, vir: 50 - --- Variable type: numeric ------------------------------------------------------ -# A tibble: 4 x 11 - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 -* -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 -3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1 -4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8 - p100 hist -* -1 7.9 ▆▇▇▅▂ -2 4.4 ▁▆▇▂▁ -3 6.9 ▇▁▆▇▂ -4 2.5 ▇▁▇▅▃ diff --git a/tests/testthat/skim_tee/grouped.txt b/tests/testthat/skim_tee/grouped.txt deleted file mode 100644 index 13bb600e..00000000 --- a/tests/testthat/skim_tee/grouped.txt +++ /dev/null @@ -1,20 +0,0 @@ -── Data Summary ──────────────────────── - Values -Name data -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - numeric 1 -________________________ -Group variables Species - -── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable Species n_missing complete_rate mean sd p0 p25 p50 p75 -1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8 5 5.2 -2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6 5.9 6.3 -3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22 6.5 6.9 - p100 -1 5.8 -2 7 -3 7.9 diff --git a/tests/testthat/skim_tee/sepal.txt b/tests/testthat/skim_tee/sepal.txt deleted file mode 100644 index 162011cc..00000000 --- a/tests/testthat/skim_tee/sepal.txt +++ /dev/null @@ -1,15 +0,0 @@ -── Data Summary ──────────────────────── - Values -Name data -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - numeric 2 -________________________ -Group variables None - -── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4 7.9 ▆▇▇▅▂ -2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3 4.4 ▁▆▇▂▁ diff --git a/tests/testthat/skim_tee/skim_tee.txt b/tests/testthat/skim_tee/skim_tee.txt deleted file mode 100644 index 7fac0954..00000000 --- a/tests/testthat/skim_tee/skim_tee.txt +++ /dev/null @@ -1,21 +0,0 @@ -── Data Summary ──────────────────────── - Values -Name data -Number of rows 71 -Number of columns 2 -_______________________ -Column type frequency: - factor 1 - numeric 1 -________________________ -Group variables None - -── Variable type: factor ─────────────────────────────────────────────────────── - skim_variable n_missing complete_rate ordered n_unique -1 feed 0 1 FALSE 6 - top_counts -1 soy: 14, cas: 12, lin: 12, sun: 12 - -── Variable type: numeric ────────────────────────────────────────────────────── - skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist -1 weight 0 1 261. 78.1 108 204. 258 324. 423 ▆▆▇▇▃ diff --git a/tests/testthat/skim_tee/species.txt b/tests/testthat/skim_tee/species.txt deleted file mode 100644 index d4fb495b..00000000 --- a/tests/testthat/skim_tee/species.txt +++ /dev/null @@ -1,16 +0,0 @@ -── Data Summary ──────────────────────── - Values -Name data -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 -________________________ -Group variables None - -── Variable type: factor ─────────────────────────────────────────────────────── - skim_variable n_missing complete_rate ordered n_unique -1 Species 0 1 FALSE 3 - top_counts -1 set: 50, ver: 50, vir: 50 diff --git a/tests/testthat/summary/summary_iris.txt b/tests/testthat/summary/summary_iris.txt deleted file mode 100644 index 8afb95b8..00000000 --- a/tests/testthat/summary/summary_iris.txt +++ /dev/null @@ -1,11 +0,0 @@ --- Data Summary ------------------------ - Values -Name iris -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None diff --git a/tests/testthat/summary/summary_iris_piped.txt b/tests/testthat/summary/summary_iris_piped.txt deleted file mode 100644 index 706c5847..00000000 --- a/tests/testthat/summary/summary_iris_piped.txt +++ /dev/null @@ -1,11 +0,0 @@ --- Data Summary ------------------------ - Values -Name Piped data -Number of rows 150 -Number of columns 5 -_______________________ -Column type frequency: - factor 1 - numeric 4 -________________________ -Group variables None diff --git a/tests/testthat/test-data.table.R b/tests/testthat/test-data-table.R similarity index 67% rename from tests/testthat/test-data.table.R rename to tests/testthat/test-data-table.R index 71672fed..aacdc5da 100644 --- a/tests/testthat/test-data.table.R +++ b/tests/testthat/test-data-table.R @@ -3,7 +3,7 @@ test_that("skim of a simple data.table produces no warnings", { skip_if_not_installed("data.table") withr::local_options(list(width = 91)) DT_letters <- data.table::data.table(abc = letters) - expect_warning(skim(DT_letters), NA) + expect_no_warning(skim(DT_letters)) }) test_that("skim of a simple data.table produces no warnings even with dtplyr", { @@ -11,7 +11,7 @@ test_that("skim of a simple data.table produces no warnings even with dtplyr", { skip_if_not_installed("dtplyr") withr::local_options(list(width = 91)) DT_letters <- data.table::data.table(abc = letters) - expect_warning(skim(DT_letters), NA) + expect_no_warning(skim(DT_letters)) }) test_that("skim of a simple data.table produces output as expected", { @@ -20,10 +20,7 @@ test_that("skim of a simple data.table produces output as expected", { skimmed_DT_letters <- skim(DT_letters) withr::local_options(list(cli.unicode = FALSE, width = 91)) - expect_print_matches_file( - skimmed_DT_letters, - "data.table/summary_DT_letters.txt" - ) + expect_snapshot(skimmed_DT_letters) }) @@ -38,27 +35,14 @@ test_that("skim of data.table produces output as expected", { ) withr::local_options(list(cli.unicode = FALSE, width = 91)) - - expect_print_matches_file( - skim(DT_factors), - "data.table/summary_DT_factors_no_key.txt" - ) + expect_snapshot(skim(DT_factors)) data.table::setkeyv(DT_factors, c("abc", "grps")) - expect_print_matches_file( - skim(DT_factors), - "data.table/summary_DT_factors.txt" - ) + expect_snapshot(skim(DT_factors)) DF_factors <- as.data.frame(DT_factors) - expect_print_matches_file( - skim(DF_factors), - "data.table/summary_DF_factors.txt" - ) + expect_snapshot(skim(DF_factors)) tibble_factors <- tibble::as_tibble(DT_factors) - expect_print_matches_file( - skim(tibble_factors), - "data.table/summary_tibble_factors.txt" - ) + expect_snapshot(skim(tibble_factors)) }) diff --git a/tests/testthat/test-dplyr.R b/tests/testthat/test-dplyr.R index c069cf31..34f9620f 100644 --- a/tests/testthat/test-dplyr.R +++ b/tests/testthat/test-dplyr.R @@ -3,28 +3,27 @@ skimmed_iris <- skim(iris) test_that("dplyr::filter works as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) - input <- dplyr::filter(skimmed_iris, skim_type == "numeric") - expect_print_matches_file(input, "dplyr/filter-skim.txt") - no_rows <- dplyr::filter(skimmed_iris, skim_type == "no_type") - expect_print_matches_file(no_rows, "dplyr/filter-no-skim.txt") + expect_snapshot({ + dplyr::filter(skimmed_iris, skim_type == "numeric") + # no rows + dplyr::filter(skimmed_iris, skim_type == "no_type") + }) }) test_that("dplyr::select works as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) with_type <- dplyr::select(skimmed_iris, skim_type, skim_variable) - expect_print_matches_file(with_type, "dplyr/select-skim.txt") - + expect_snapshot(with_type) without_type <- dplyr::select(skimmed_iris, numeric.mean) - withr::local_options(list(cli.unicode = FALSE)) - expect_print_matches_file(without_type, "dplyr/select-no-skim.txt") + expect_snapshot(without_type) }) test_that("dplyr::mutate works as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) input <- dplyr::mutate(skimmed_iris, mean2 = numeric.mean^2) - expect_print_matches_file(input, "dplyr/mutate-skim.txt") + expect_snapshot(input) no_variable <- dplyr::mutate(skimmed_iris, skim_variable = NULL) identical( @@ -37,12 +36,11 @@ test_that("dplyr::slice works as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) input <- dplyr::slice(skimmed_iris, 1:3) - expect_print_matches_file(input, "dplyr/slice.txt") + expect_snapshot(input) }) test_that("dplyr::arrange works as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) - input <- dplyr::arrange(skimmed_iris, desc(numeric.mean)) - expect_print_matches_file(input, "dplyr/arrange.txt") + expect_snapshot(dplyr::arrange(skimmed_iris, desc(numeric.mean))) }) diff --git a/tests/testthat/test-reshape.R b/tests/testthat/test-reshape.R index d8d9bdaa..7f5deab7 100644 --- a/tests/testthat/test-reshape.R +++ b/tests/testthat/test-reshape.R @@ -85,7 +85,7 @@ test_that("focus() matches select(data, skim_type, skim_variable, ...)", { expected <- dplyr::select( skimmed, skim_type, skim_variable, n_missing ) - expect_equal(focus(skimmed, n_missing), expected, check.attributes = FALSE) + expect_equal(focus(skimmed, n_missing), expected, ignore_attr = "skimmers_used") }) test_that("focus() does not allow dropping skim metadata columns", { @@ -110,22 +110,22 @@ test_that("to_long() returns a long tidy data frame with 4 columns", { names(skimmed_long), c("skim_type", "skim_variable", "stat", "formatted") ) - expect_equal(length(unique(skimmed_long$stat)), 13) - expect_equal(length(unique(skimmed_long$skim_type)), 2) - expect_equal(length(unique(skimmed_long$skim_variable)), 5) + expect_length(unique(skimmed_long$stat), 13) + expect_length(unique(skimmed_long$skim_type), 2) + expect_length(unique(skimmed_long$skim_variable), 5) }) test_that("to_long() on a skim_df returns a long tidy df with 4 columns", { skimmed_long <- to_long(skim(iris)) # Statistics from the skim_df with values of NA are not included expect_n_rows(skimmed_long, 45) - expect_equal( - names(skimmed_long), + expect_named( + skimmed_long, c("skim_type", "skim_variable", "stat", "formatted") ) - expect_equal(length(unique(skimmed_long$stat)), 13) - expect_equal(length(unique(skimmed_long$skim_type)), 2) - expect_equal(length(unique(skimmed_long$skim_variable)), 5) + expect_length(unique(skimmed_long$stat), 13) + expect_length(unique(skimmed_long$skim_type), 2) + expect_length(unique(skimmed_long$skim_variable), 5) }) test_that("to_long() on a df and a skim_df from same df are identical", { diff --git a/tests/testthat/test-sfl.R b/tests/testthat/test-sfl.R index 150c7348..8b5c06fe 100644 --- a/tests/testthat/test-sfl.R +++ b/tests/testthat/test-sfl.R @@ -22,7 +22,7 @@ test_that("The interface for sfl's separates keep and drop functions", { test_that("sfl's support dummy names", { input <- sfl(mean = ~ mean(., na.rm = TRUE), skim_type = "test") funs <- input$funs - expect_equal(funs$mean, rlang::quo(mean(., na.rm = TRUE))) + expect_equal(funs$mean, rlang::quo(mean(., na.rm = TRUE)), ignore_attr = "class") }) test_that("sfl's automatically generate function names", { diff --git a/tests/testthat/test-skim.R b/tests/testthat/test-skim.R index 2277364e..21668b4f 100644 --- a/tests/testthat/test-skim.R +++ b/tests/testthat/test-skim.R @@ -6,10 +6,7 @@ test_that("skim returns expected response for numeric vectors", { expect_n_columns(input, 12) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "numeric.mean", "numeric.sd", "numeric.p0", "numeric.p25", @@ -196,10 +193,7 @@ test_that("skim returns expected response for character vectors", { expect_n_columns(input, 9) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "character.min", "character.max", "character.empty", @@ -237,10 +231,7 @@ test_that("skim returns expected response for logical vectors", { expect_n_columns(input, 6) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "logical.mean", "logical.count" @@ -287,10 +278,7 @@ test_that("skim returns expected response for complex vectors", { expect_n_columns(input, 5) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named( input, c( @@ -317,7 +305,7 @@ test_that("skim returns expected response for complex vectors", { }) test_that("skim returns expected response for Date vectors", { - dat <- seq(as.Date("2011-07-01"), by = 1, len = 9) + dat <- seq(as.Date("2011-07-01"), by = 1, length.out = 9) x <- tibble::tibble(dat) input <- skim(x) @@ -326,10 +314,7 @@ test_that("skim returns expected response for Date vectors", { expect_n_columns(input, 8) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "Date.min", "Date.max", "Date.median", "Date.n_unique" @@ -364,10 +349,7 @@ test_that("skim returns expected response for ts vectors", { expect_n_columns(input, 14) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "ts.start", "ts.end", "ts.frequency", "ts.deltat", "ts.mean", "ts.sd", @@ -397,7 +379,7 @@ test_that("skim returns expected response for ts vectors", { expect_equal(input$ts.frequency, 4) expect_equal(input$ts.deltat, 0.25) expect_equal(input$ts.mean, 9.31, tolerance = 0.001) - expect_equal(input$ts.sd, 0.316, tolerance = 0.001) + expect_equal(input$ts.sd, 0.316, tolerance = 0.01) expect_equal(input$ts.min, 8.79, tolerance = 0.001) expect_equal(input$ts.max, 9.79, tolerance = 0.001) expect_equal(input$ts.median, 9.31, tolerance = 0.001) @@ -405,7 +387,7 @@ test_that("skim returns expected response for ts vectors", { }) test_that("skim returns expected response for POSIXct vectors", { - dat <- seq(as.POSIXct("2011-07-01 00:00:00", tz = "UTC"), by = 1, len = 10) + dat <- seq(as.POSIXct("2011-07-01 00:00:00", tz = "UTC"), by = 1, length.out = 10) dat[2] <- NA posix <- tibble::tibble(dat) input <- skim(posix) @@ -415,10 +397,7 @@ test_that("skim returns expected response for POSIXct vectors", { expect_n_columns(input, 8) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "POSIXct.min", "POSIXct.max", "POSIXct.median", @@ -472,10 +451,7 @@ test_that("skim returns expected response for list (not AsIs) vectors", { expect_n_columns(input, 7) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "list.n_unique", "list.min_length", "list.max_length" @@ -511,10 +487,7 @@ test_that("skim returns expected response for list with all NA's", { expect_n_columns(input, 7) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "list.n_unique", "list.min_length", "list.max_length" @@ -550,10 +523,7 @@ test_that("skim returns expected response for asis vectors", { expect_n_columns(input, 7) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "AsIs.n_unique", "AsIs.min_length", "AsIs.max_length" @@ -591,10 +561,7 @@ test_that("skim returns expected response for difftime vectors", { expect_n_columns(input, 8) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "difftime.min", "difftime.max", "difftime.median", @@ -632,10 +599,7 @@ test_that("skim returns expected response for lubridate Timespan vectors", { expect_n_columns(input, 8) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "Timespan.min", "Timespan.max", "Timespan.median", @@ -673,10 +637,7 @@ test_that("skim handles objects containing haven_labelled vectors: double", { expect_n_columns(input, 12) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "numeric.mean", "numeric.sd", "numeric.p0", "numeric.p25", @@ -722,10 +683,7 @@ test_that("skim handles objects containing haven_labelled vectors: character", { expect_n_columns(input, 9) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "character.min", "character.max", "character.empty", @@ -755,7 +713,7 @@ test_that("skim handles objects containing haven_labelled vectors: character", { }) test_that("skim handles objects with multiple classes", { - dat <- seq(as.Date("2011-07-01"), by = 1, len = 10) + dat <- seq(as.Date("2011-07-01"), by = 1, length.out = 10) dat[2] <- NA class(dat) <- c("strange_type", "Date") x <- tibble::tibble(dat) @@ -766,10 +724,7 @@ test_that("skim handles objects with multiple classes", { expect_n_columns(input, 8) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "Date.min", "Date.max", "Date.median", "Date.n_unique" @@ -787,10 +742,7 @@ test_that("skim treats unknown classes as character", { expect_warning(input <- skim(x)) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "character.min", "character.max", "character.empty", @@ -819,10 +771,7 @@ test_that("skim handles objects with two unknown classes", { expect_warning(input <- skim(x)) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "character.min", "character.max", "character.empty", @@ -852,10 +801,7 @@ test_that("Skimming a complete data frame works as expected", { expect_n_columns(input, 15) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "n_missing", "complete_rate", "factor.ordered", "factor.n_unique", "factor.top_counts", @@ -880,17 +826,14 @@ test_that("Skimming a complete data frame works as expected", { test_that("successfully skim mixed data types with common skimmers", { df <- data.frame( - Date = seq(as.Date("2011-07-01"), by = 1, len = 10), + Date = seq(as.Date("2011-07-01"), by = 1, length.out = 10), POSIXct = as.POSIXct("2011-07-01 00:00:00", tz = "UTC") ) input <- skim(df) expect_n_rows(input, 2) expect_n_columns(input, 12) - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named( input, c( @@ -952,10 +895,7 @@ test_that("Skimming a grouped df with selections works as expected", { expect_n_columns(input, 14) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "cyl", "gear", "n_missing", "complete_rate", "numeric.mean", "numeric.sd", "numeric.p0", @@ -983,10 +923,7 @@ test_that("Skimming a grouped df works when selecting exactly one variable", { expect_n_columns(input, 14) # classes - expect_s3_class(input, "skim_df") - expect_s3_class(input, "tbl_df") - expect_s3_class(input, "tbl") - expect_s3_class(input, "data.frame") + expect_s3_class(input, c("skim_df", "tbl_df", "tbl", "data.frame")) expect_named(input, c( "skim_type", "skim_variable", "cyl", "gear", "n_missing", "complete_rate", "numeric.mean", "numeric.sd", "numeric.p0", diff --git a/tests/testthat/test-skim_print.R b/tests/testthat/test-skim_print.R index 28546759..64bc2ec5 100644 --- a/tests/testthat/test-skim_print.R +++ b/tests/testthat/test-skim_print.R @@ -1,26 +1,25 @@ test_that("Skim prints a header for the entire output and each type", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) - input <- skim(iris) - expect_print_matches_file(input, "print/default.txt") - - input$numeric.hist <- NULL - expect_print_matches_file(input, "print/no-hist.txt") + expect_snapshot({ + input <- skim(iris) + input + input$numeric.hist <- NULL + input + }) }) test_that("Skim prints a special header for grouped data frames", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) - input <- skim(dplyr::group_by(iris, Species)) - expect_print_matches_file(input, "print/groups.txt") + expect_snapshot( skim(dplyr::group_by(iris, Species))) }) test_that("Skim lists print as expected", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) - input <- partition(skimmed) - expect_print_matches_file(input, "print/list.txt") + expect_snapshot(partition(skimmed)) }) test_that("knit_print produces expected results", { @@ -30,23 +29,23 @@ test_that("knit_print produces expected results", { input <- knit_print(skimmed) expect_s3_class(input, "knit_asis") expect_length(input, 1) - expect_matches_file(input, "print/knit_print.txt") + expect_snapshot(cat(input)) }) test_that("knit_print works with skim summaries", { withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) summarized <- summary(skimmed) - input <- knitr::knit_print(summarized) - expect_matches_file(input, "print/knit_print-summary.txt") + expect_snapshot(cat(knitr::knit_print(summarized))) }) test_that("knit_print appropriately falls back to tibble printing", { withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) reduced <- dplyr::select(skimmed, skim_variable, numeric.mean) - printed <- testthat::capture_output(input <- knitr::knit_print(reduced)) - expect_matches_file(printed, "print/knit_print-fallback.txt") + expect_snapshot({ + input <- knitr::knit_print(reduced) + }) expect_s3_class(input, "data.frame") }) @@ -55,8 +54,7 @@ test_that("Summaries can be suppressed within knitr", { withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) options <- list(skimr_include_summary = FALSE) - input <- knitr::knit_print(skimmed, options = options) - expect_matches_file(input, "print/knit_print-suppressed.txt") + expect_snapshot(cat(knitr::knit_print(skimmed, options = options))) }) test_that("Skim lists have a separate knit_print method", { @@ -64,55 +62,48 @@ test_that("Skim lists have a separate knit_print method", { withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) skim_list <- partition(skimmed) - input <- knit_print(skim_list) - expect_matches_file(input, "print/knit_print-skim_list.txt") + expect_snapshot(cat(knit_print(skim_list))) }) test_that("You can yank a type from a skim_df and call knit_print", { withr::local_options(list(cli.unicode = FALSE)) skimmed <- skim(iris) skim_one <- yank(skimmed, "factor") - input <- knit_print(skim_one) - expect_matches_file(input, "print/knit_print-yank.txt") + expect_snapshot(cat(knit_print(skim_one))) }) test_that("Skim falls back to tibble::print.tbl() appropriately", { withr::local_options(list(cli.unicode = FALSE)) - input <- skim(iris) - mean_only <- dplyr::select(input, numeric.mean) - expect_print_matches_file(mean_only, "print/fallback.txt") + + expect_snapshot({ + input <- skim(iris) + dplyr::select(input, numeric.mean) + }) }) test_that("Print focused objects appropriately", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) skimmed <- skim(iris) - input <- focus(skimmed, n_missing) - expect_print_matches_file(input, "print/focus.txt") + expect_snapshot(focus(skimmed, n_missing)) }) test_that("Support for smaller consoles can be set with the width option", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) - skimmed <- skim(iris) - expect_print_matches_file(skimmed, "print/smaller.txt", width = 50) + expect_snapshot(skim(iris)) }) test_that("Table header width can be controlled by an option", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) skimmed <- skim(iris) - expect_print_matches_file( - skimmed, - "print/narrow-header.txt", - skimr_table_header_width = 50 - ) + expect_snapshot(skimmed) }) test_that("skimr creates appropriate output for Jupyter", { withr::local_options(list(cli.unicode = FALSE)) skip_if_not(l10n_info()$`UTF-8`) skimmed <- skim(iris) - input <- testthat::capture_output(repr_text(skimmed)) - expect_matches_file(input, "print/repr.txt") + expect_snapshot(skimmed) }) diff --git a/tests/testthat/test-skim_tee.R b/tests/testthat/test-skim_tee.R index 26af8bb0..7af460c1 100644 --- a/tests/testthat/test-skim_tee.R +++ b/tests/testthat/test-skim_tee.R @@ -1,21 +1,24 @@ test_that("Using skim_tee prints returns the object", { skip_if_not(l10n_info()$`UTF-8`) - input <- testthat::capture_output(skim_object <- skim_tee(chickwts)) - expect_matches_file(input, "skim_tee/skim_tee.txt") + expect_snapshot({ + skim_object <- skim_tee(chickwts) + }) expect_identical(chickwts, skim_object) }) test_that("skim_tee prints only selected columns, but returns full object", { skip_if_not(l10n_info()$`UTF-8`) - input <- testthat::capture_output(obj <- skim_tee(iris, Species)) - expect_matches_file(input, "skim_tee/species.txt") + expect_snapshot({ + obj <- skim_tee(iris, Species) + }) expect_identical(obj, iris) }) test_that("skim_tee supports dplyr helpers", { skip_if_not(l10n_info()$`UTF-8`) - input <- testthat::capture_output(obj <- skim_tee(iris, starts_with("Sepal"))) - expect_matches_file(input, "skim_tee/sepal.txt") + expect_snapshot({ + obj <- skim_tee(iris, starts_with("Sepal")) + }) expect_identical(obj, iris) }) @@ -23,9 +26,8 @@ test_that("Skim_tee works with groups", { skip_if_not(l10n_info()$`UTF-8`) iris_grouped <- dplyr::group_by(iris, Species) my_skim <- skim_with(numeric = sfl(hist = NULL)) - input <- testthat::capture_output( + expect_snapshot({ obj <- skim_tee(iris_grouped, Sepal.Length, skim_fun = my_skim) - ) - expect_matches_file(input, "skim_tee/grouped.txt") + }) expect_identical(obj, iris_grouped) }) diff --git a/tests/testthat/test-skim_with.R b/tests/testthat/test-skim_with.R index d94f018f..2cc4f55e 100644 --- a/tests/testthat/test-skim_with.R +++ b/tests/testthat/test-skim_with.R @@ -135,10 +135,8 @@ test_that("An empty call to skim_with() returns the default skim()", { }) test_that("User-defined defaults require sfl's with class names", { - with_mock( - get_skimmers = function(column) sfl(length), - expect_error(skim(data.frame(1)), "Default skimming functions") - ) + local_mocked_bindings(get_skimmers = function(column) sfl(length)) + expect_error(skim(data.frame(1)), "Default skimming functions") }) test_that("Sfl's can be passed as an unquoted list", { @@ -168,8 +166,8 @@ test_that("Doubles and integers are both 'numeric'", { test_that("Defining an integer sfl changes behavior", { df <- data.frame(int = 1:3, dbl = 1:3 + 0.5) - my_skim <- expect_message( - skim_with( + expect_message( + my_skim <- skim_with( numeric = sfl(hist = NULL), integer = sfl(int_mean = mean) ) ) diff --git a/tests/testthat/test-summary.R b/tests/testthat/test-summary.R index 91f9f3b8..c44454bd 100644 --- a/tests/testthat/test-summary.R +++ b/tests/testthat/test-summary.R @@ -20,11 +20,7 @@ test_that("The summary print method prints the correct object", { skip_if_not(l10n_info()$`UTF-8`) withr::local_options(list(cli.unicode = FALSE)) skim_summary_input <- summary(skim(iris)) - expect_known_output( - skim_summary_input, "summary/summary_iris.txt", - update = FALSE, - print = TRUE - ) + expect_snapshot(skim_summary_input) }) test_that("The summary print method prints the correct object when piped", { @@ -34,9 +30,7 @@ test_that("The summary print method prints the correct object when piped", { summary_input <- iris %>% skim() %>% summary() - expect_known_output(summary_input, "summary/summary_iris_piped.txt", - update = FALSE, print = TRUE - ) + expect_snapshot(summary_input) }) test_that("null object gets expected message", { diff --git a/tests/testthat/test-vctrs.R b/tests/testthat/test-vctrs.R index 611893f3..f1fd3f9e 100644 --- a/tests/testthat/test-vctrs.R +++ b/tests/testthat/test-vctrs.R @@ -19,7 +19,7 @@ test_that("You can bind skim_df rows", { test_that("When binding columns, fall back to tbl_df", { skimmed <- skim(iris) - combined <- vctrs::vec_cbind(skimmed, skimmed) + combined <- vctrs::vec_cbind(skimmed, skimmed, .name_repair = "universal_quiet") expect_s3_class(combined, "tbl") expect_false("skim_df" %in% class(combined)) })