diff --git a/.Rbuildignore b/.Rbuildignore index adcaca8..1202d72 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,4 @@ ^revdep$ ^hex_descriptr\.png$ ^\.github$ +TODO.md diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b0f3cd6..3cdf68c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,16 +1,14 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +# 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: - - master - - develop + branches: [master, develop] pull_request: - branches: - - master - - develop + branches: [master, develop] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -22,63 +20,33 @@ jobs: fail-fast: false matrix: config: + - {os: macos-latest, r: 'release'} - {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"} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true - - 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 + - uses: r-lib/actions/setup-r-dependencies@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: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + extra-packages: any::rcmdcheck + needs: check - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 0000000..74ec7b0 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,95 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9245d3a..5679b54 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,48 +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: - - master - - develop + branches: [master, develop] pull_request: - branches: - - master - - develop + branches: [master, develop] -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr, any::xml2 + needs: coverage - - name: Query dependencies + - name: Test coverage 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") + 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: Cache R packages - uses: actions/cache@v2 + - uses: codecov/codecov-action@v4 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 + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() run: | - install.packages(c("remotes")) - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("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 8f2b677..711a927 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,6 @@ Imports: rlang, scales, stats, - tibble, tidyr, utils Suggests: @@ -24,7 +23,7 @@ Suggests: gridExtra, knitr, rmarkdown, - testthat, + testthat (>= 3.0.0), vdiffr, xplorerr License: MIT + file LICENSE @@ -33,4 +32,5 @@ BugReports: https://github.com/rsquaredacademy/descriptr/issues Encoding: UTF-8 LazyData: true VignetteBuilder: knitr -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 +Config/testthat/edition: 3 diff --git a/R/ds-cross-table.R b/R/ds-cross-table.R index 0e2c2fe..d0b2cc7 100644 --- a/R/ds-cross-table.R +++ b/R/ds-cross-table.R @@ -124,7 +124,8 @@ plot.ds_cross_table <- function(x, stacked = FALSE, proportional = FALSE, use_series(data) %>% dplyr::select(x = !! k, y = !! j) %>% table() %>% - tibble::as_tibble() %>% + as.data.frame() %>% + set_colnames(c("x", "y", "n")) %>% ggplot(aes(x = x, y = n, fill = y)) + geom_bar(stat = "identity", position = "fill") + scale_y_continuous(labels = scales::percent_format()) + diff --git a/R/ds-describe.R b/R/ds-describe.R index 5f232b4..da2bd7f 100644 --- a/R/ds-describe.R +++ b/R/ds-describe.R @@ -123,7 +123,7 @@ ds_measures_variation <- function(data, ..., decimals = 2) { sd = stats::sd, coeff_var = ds_cvar, std_error = ds_std_error)) %>% - tibble::as_tibble() + as.data.frame() } else if (is.numeric(data)) { @@ -211,7 +211,7 @@ ds_measures_symmetry <- function(data, ..., decimals = 2) { skewness = ds_skewness, kurtosis = ds_kurtosis) ) %>% - tibble::as_tibble() + as.data.frame() } else if (is.numeric(data)) { @@ -304,7 +304,7 @@ ds_percentiles <- function(data, ..., decimals = 2) { per_99 = ~ quantile(., 0.99), max = max) ) %>% - tibble::as_tibble() + as.data.frame() } else if (is.numeric(data)) { @@ -374,13 +374,16 @@ ds_extreme_obs <- function(data, col, decimals = 2) { na.omit() %>% dplyr::pull(1) - tibble::tibble(type = c(rep("high", 5), rep("low", 5)), + result <- data.frame(type = c(rep("high", 5), rep("low", 5)), value = c(ds_tailobs(na_data, 5, "high"), - ds_tailobs(na_data, 5, "low")), - index = ds_rindex(na_data, value)) + ds_tailobs(na_data, 5, "low"))) + + result$index <- ds_rindex(na_data, result$value) + return(result) } else if (is.numeric(data)) { + data <- na.omit(data) result <- data.frame(type = c(rep("high", 5), rep("low", 5)), value = c(round(ds_tailobs(data, 5, "high"), decimals), round(ds_tailobs(data, 5, "low"), decimals))) diff --git a/R/ds-descriptr.R b/R/ds-descriptr.R index 3befc8f..8b74a91 100644 --- a/R/ds-descriptr.R +++ b/R/ds-descriptr.R @@ -2,20 +2,22 @@ #' #' Generate descriptive statistics and explore statistical distributions #' -#' @import stats +#' @import stats #' @import ggplot2 #' @import magrittr #' #' @docType package +#' @keywords internal #' @name descriptr -NULL +#' @aliases descriptr-package +"_PACKAGE" ## quiets concerns of R CMD check re: the .'s that appear in pipelines if (getRversion() >= "2.15.1") { globalVariables(c( ".", "breaks", "Levels", "varyable", "count", "cumulative", "frequency", "values", "s", "tp", "type", "xvar", "yvar", - "data", "varnames", "frequency", "varname", "bins", "n", "value", "y", " - count" + "data", "varnames", "frequency", "varname", "bins", "n", "value", "y", + "count", "plot_data", "utility" )) } diff --git a/R/ds-freq-factor.R b/R/ds-freq-factor.R index 34f8bbd..4789ca7 100644 --- a/R/ds-freq-factor.R +++ b/R/ds-freq-factor.R @@ -32,7 +32,7 @@ ds_freq_factor <- function(data, variable) { per <- percent(result, data_len) cum_per <- percent(cum, data_len) - ftable <- tibble::tibble( + ftable <- data.frame( Levels = level_names, Frequency = result, `Cum Frequency` = cum, diff --git a/R/ds-freq-mult.R b/R/ds-freq-mult.R index dab2bec..1a07917 100644 --- a/R/ds-freq-mult.R +++ b/R/ds-freq-mult.R @@ -23,7 +23,7 @@ freq_table2.default <- function(data, name) { per <- percent(result, data_len) cum_per <- percent(cum, data_len) - ftable <- tibble::tibble( + ftable <- data.frame( Levels = level_names, Frequency = result, `Cum Frequency` = cum, diff --git a/R/ds-freq-numeric.R b/R/ds-freq-numeric.R index b094acc..78b00e7 100644 --- a/R/ds-freq-numeric.R +++ b/R/ds-freq-numeric.R @@ -51,7 +51,7 @@ ds_freq_numeric <- function(data, variable, bins = 5) { lower_n <- n_bins + 1 freq_data <- - tibble::tibble(lower = inta[-lower_n], + data.frame(lower = inta[-lower_n], upper = inta[-1], frequency = result, cumulative = cum, @@ -96,11 +96,7 @@ plot_ds_freq_numeric <- function(x, ...) { length() p <- - x %>% - use_series(utility) %>% - use_series(frequency) %>% - tibble::enframe(name = NULL) %>% - tibble::add_column(x = seq_len(x$utility$bins), .before = 1) %>% + data.frame(x = seq_len(x$utility$bins), value = x$utility$frequency) %>% ggplot() + geom_col( aes(x = x, y = value), width = 0.999, diff --git a/R/ds-group-summary.R b/R/ds-group-summary.R index 60ff976..ce6d912 100644 --- a/R/ds-group-summary.R +++ b/R/ds-group-summary.R @@ -129,7 +129,7 @@ plot.ds_group_summary <- function(x, print_plot = TRUE, ...) { x %>% use_series(plot_data) %>% ggplot() + - geom_boxplot(aes_string(x = x_lab, y = y_lab), fill = "blue") + + geom_boxplot(aes(x = .data[[x_lab]], y = .data[[y_lab]]), fill = "blue") + xlab(x_lab) + ylab(y_lab) + ggtitle(paste(y_lab, "by", x_lab)) diff --git a/R/ds-output.R b/R/ds-output.R index fd12705..b66937f 100644 --- a/R/ds-output.R +++ b/R/ds-output.R @@ -328,7 +328,7 @@ print_ftable <- function(x) { nc <- ncol(x$ftable) w1 <- max(nchar("Levels"), nchar(x$ftable$Levels), nchar("Missing")) w2 <- max(nchar("Frequency"), nchar(x$ftable$Frequency), nchar(x$utility$na_count)) - w3 <- max(nchar("Cum Frequency"), nchar(x$ftable$`Cum Frequency`)) + w3 <- max(nchar("Cum Frequency"), nchar(x$ftable$Cum.Frequency)) w <- sum(w1, w2, w3, 26, 16) cat(format(paste("Variable:", x$utility$varname), width = w, justify = "centre"), "\n") cat(rep("-", w), sep = "") @@ -343,9 +343,9 @@ print_ftable <- function(x) { cat("\n") cat(format(as.character(x$ftable$Levels[i]), width = w1, justify = "centre"), fs(), format(as.character(x$ftable$Frequency[i]), width = w2, justify = "centre"), fs(), - format(as.character(x$ftable$`Cum Frequency`[i]), width = w3, justify = "centre"), fs(), + format(as.character(x$ftable$Cum.Frequency[i]), width = w3, justify = "centre"), fs(), format(as.character(x$ftable$Percent[i]), width = 13, justify = "centre"), fs(), - format(as.character(x$ftable$`Cum Percent`[i]), width = 13, justify = "centre") + format(as.character(x$ftable$Cum.Percent[i]), width = 13, justify = "centre") ) cat("\n") cat(rep("-", w), sep = "") @@ -378,7 +378,7 @@ print_ftable2 <- function(x) { nc <- ncol(x$ftable) w1 <- max(nchar("Levels"), nchar(x$ftable$Levels), nchar("Missing")) w2 <- max(nchar("Frequency"), nchar(x$ftable$Frequency), nchar(x$na_count)) - w3 <- max(nchar("Cum Frequency"), nchar(x$ftable$`Cum Frequency`)) + w3 <- max(nchar("Cum Frequency"), nchar(x$ftable$Cum.Frequency)) w <- sum(w1, w2, w3, 26, 16) cat(format(paste("Variable:", x$varname), width = w, justify = "centre"), "\n") cat(rep("-", w), sep = "") @@ -393,9 +393,9 @@ print_ftable2 <- function(x) { cat("\n") cat(format(as.character(x$ftable$Levels[i]), width = w1, justify = "centre"), fs(), format(as.character(x$ftable$Frequency[i]), width = w2, justify = "centre"), fs(), - format(as.character(x$ftable$`Cum Frequency`[i]), width = w3, justify = "centre"), fs(), + format(as.character(x$ftable$Cum.Frequency[i]), width = w3, justify = "centre"), fs(), format(as.character(x$ftable$Percent[i]), width = 13, justify = "centre"), fs(), - format(as.character(x$ftable$`Cum Percent`[i]), width = 13, justify = "centre") + format(as.character(x$ftable$Cum.Percent[i]), width = 13, justify = "centre") ) cat("\n") cat(rep("-", w), sep = "") diff --git a/R/ds-summary-stats.R b/R/ds-summary-stats.R index 0764fae..86bc05e 100644 --- a/R/ds-summary-stats.R +++ b/R/ds-summary-stats.R @@ -2,10 +2,13 @@ #' #' @description Range of descriptive statistics for continuous data. #' -#' @param data A \code{data.frame} or \code{tibble}. +#' @param data An object of type \code{numeric} or \code{data.frame}. #' @param ... Column(s) in \code{data}. #' #' @examples +#' # numeric data +#' ds_summary_stats(mtcarz$mpg) +#' #' # single variable #' ds_summary_stats(mtcarz, mpg) #' @@ -25,50 +28,58 @@ #' ds_summary_stats <- function(data, ...) { - check_df(data) + if (is.numeric(data)) { + print(ds_summary(data)) + } else { - var <- rlang::quos(...) + check_df(data) + var <- rlang::quos(...) - if (length(var) < 1) { - is_num <- sapply(data, is.numeric) - if (!any(is_num == TRUE)) { - stop("Data has no continuous variables.", call. = FALSE) + if (length(var) < 1) { + is_num <- sapply(data, is.numeric) + if (!any(is_num == TRUE)) { + stop("Data has no continuous variables.", call. = FALSE) + } + data <- data[is_num] + } else { + data %<>% + dplyr::select(!!! var) + is_num <- sapply(data, is.numeric) + if (!any(is_num == TRUE)) { + stop("Data has no continuous variables.", call. = FALSE) + } } - data <- data[is_num] - } else { - data %<>% - dplyr::select(!!! var) - is_num <- sapply(data, is.numeric) - if (!any(is_num == TRUE)) { - stop("Data has no continuous variables.", call. = FALSE) - } - } - col_names <- names(data) - for (i in col_names) { - ds_rule(paste0('Variable: ', i)) - cat('\n\n') - print(ds_summary(data, i)) - cat('\n\n\n') + col_names <- names(data) + for (i in col_names) { + ds_rule(paste0('Variable: ', i)) + cat('\n\n') + print(ds_summary(data, i)) + cat('\n\n\n') + } } - } ds_summary <- function(data, variable) UseMethod("ds_summary") ds_summary.default <- function(data, variable) { - check_df(data) - vary <- rlang::enquo(variable) - var_name <- deparse(substitute(variable)) - check_numeric(data, !! vary, var_name) + if (is.numeric(data)) { + odata <- data + sdata <- na.omit(data) + } else { + check_df(data) + vary <- rlang::enquo(variable) + var_name <- deparse(substitute(variable)) + check_numeric(data, !! vary, var_name) - odata <- dplyr::pull(data, !! vary) + odata <- dplyr::pull(data, !! vary) - sdata <- - data %>% - dplyr::pull(!! vary) %>% - na.omit() + sdata <- + data %>% + dplyr::pull(!! vary) %>% + na.omit() + } low <- ds_tailobs(sdata, 5, "low") high <- ds_tailobs(sdata, 5, "high") @@ -76,36 +87,36 @@ ds_summary.default <- function(data, variable) { high_val <- ds_rindex(sdata, high) result <- - list(obs = length(odata), - missing = sum(is.na(odata)), - avg = mean(sdata), - tavg = mean(sdata, trim = 0.05), - stdev = sd(sdata), - variance = var(sdata), - skew = ds_skewness(sdata), - kurtosis = ds_kurtosis(sdata), - uss = stat_uss(sdata), - css = ds_css(sdata), - cvar = ds_cvar(sdata), - sem = ds_std_error(sdata), - median = median(sdata), - mode = ds_mode(sdata), - range = ds_range(sdata), - min = min(sdata), - Max = max(sdata), - iqrange = IQR(sdata), - per99 = quantile(sdata, 0.99), - per90 = quantile(sdata, 0.90), - per95 = quantile(sdata, 0.95), - per75 = quantile(sdata, 0.75), - per25 = quantile(sdata, 0.25), - per10 = quantile(sdata, 0.10), - per5 = quantile(sdata, 0.05), - per1 = quantile(sdata, 0.01), - lowobs = low, - highobs = high, - lowobsi = low_val, - highobsi = high_val) + list(obs = length(odata), + missing = sum(is.na(odata)), + avg = mean(sdata), + tavg = mean(sdata, trim = 0.05), + stdev = sd(sdata), + variance = var(sdata), + skew = ds_skewness(sdata), + kurtosis = ds_kurtosis(sdata), + uss = stat_uss(sdata), + css = ds_css(sdata), + cvar = ds_cvar(sdata), + sem = ds_std_error(sdata), + median = median(sdata), + mode = ds_mode(sdata), + range = ds_range(sdata), + min = min(sdata), + Max = max(sdata), + iqrange = IQR(sdata), + per99 = quantile(sdata, 0.99), + per90 = quantile(sdata, 0.90), + per95 = quantile(sdata, 0.95), + per75 = quantile(sdata, 0.75), + per25 = quantile(sdata, 0.25), + per10 = quantile(sdata, 0.10), + per5 = quantile(sdata, 0.05), + per1 = quantile(sdata, 0.01), + lowobs = low, + highobs = high, + lowobsi = low_val, + highobsi = high_val) class(result) <- "ds_summary" return(result) diff --git a/README.Rmd b/README.Rmd index 4b24f54..1fe7e43 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,9 +17,9 @@ knitr::opts_chunk$set( > Generate descriptive statistics -[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/descriptr)](https://cran.r-project.org/package=descriptr) [![cran checks](https://cranchecks.info/badges/summary/descriptr)](https://cran.r-project.org/web/checks/check_results_descriptr.html) ![r-universe](https://rsquaredacademy.r-universe.dev/badges/descriptr) -[![R build status](https://github.com/rsquaredacademy/descriptr/workflows/R-CMD-check/badge.svg)](https://github.com/rsquaredacademy/descriptr/actions) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) -[![Coverage status](https://codecov.io/gh/rsquaredacademy/descriptr/branch/master/graph/badge.svg)](https://codecov.io/github/rsquaredacademy/descriptr?branch=master) [![status](https://tinyverse.netlify.com/badge/descriptr)](https://CRAN.R-project.org/package=descriptr) [![](https://cranlogs.r-pkg.org/badges/grand-total/descriptr)](https://cran.r-project.org/package=descriptr) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/descriptr)](https://cran.r-project.org/package=descriptr) +[![R-CMD-check](https://github.com/rsquaredacademy/descriptr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/descriptr/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/rsquaredacademy/descriptr/graph/badge.svg)](https://app.codecov.io/gh/rsquaredacademy/descriptr) diff --git a/README.md b/README.md index 0769b38..cb1bb28 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,10 @@ -[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/descriptr)](https://cran.r-project.org/package=descriptr) -[![cran -checks](https://cranchecks.info/badges/summary/descriptr)](https://cran.r-project.org/web/checks/check_results_descriptr.html) -![r-universe](https://rsquaredacademy.r-universe.dev/badges/descriptr) -[![R build -status](https://github.com/rsquaredacademy/descriptr/workflows/R-CMD-check/badge.svg)](https://github.com/rsquaredacademy/descriptr/actions) -[![Lifecycle: -stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) -[![Coverage -status](https://codecov.io/gh/rsquaredacademy/descriptr/branch/master/graph/badge.svg)](https://codecov.io/github/rsquaredacademy/descriptr?branch=master) -[![status](https://tinyverse.netlify.com/badge/descriptr)](https://CRAN.R-project.org/package=descriptr) -[![](https://cranlogs.r-pkg.org/badges/grand-total/descriptr)](https://cran.r-project.org/package=descriptr) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/descriptr)](https://cran.r-project.org/package=descriptr) +[![R-CMD-check](https://github.com/rsquaredacademy/descriptr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/descriptr/actions/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/rsquaredacademy/descriptr/graph/badge.svg)](https://app.codecov.io/gh/rsquaredacademy/descriptr) ## Installation @@ -37,11 +29,11 @@ install.packages("descriptr", repos = "https://rsquaredacademy.r-universe.dev") ## Articles -- [Continuous - Data](https://descriptr.rsquaredacademy.com/articles/continuous-data.html) -- [Categorical - Data](https://descriptr.rsquaredacademy.com/articles/categorical-data.html) -- [Visualization](https://descriptr.rsquaredacademy.com/articles/visualization.html) +- [Continuous + Data](https://descriptr.rsquaredacademy.com/articles/continuous-data.html) +- [Categorical + Data](https://descriptr.rsquaredacademy.com/articles/categorical-data.html) +- [Visualization](https://descriptr.rsquaredacademy.com/articles/visualization.html) ## Usage @@ -224,25 +216,25 @@ ds_group_summary(mtcarz, cyl, mpg) ``` r ds_tidy_stats(mtcarz, mpg, disp, hp) -#> # A tibble: 3 x 16 +#> # A tibble: 3 × 16 #> vars min max mean t_mean median mode range variance stdev skew #> #> 1 disp 71.1 472 231. 228 196. 276. 401. 15361. 124. 0.420 #> 2 hp 52 335 147. 144. 123 110 283 4701. 68.6 0.799 #> 3 mpg 10.4 33.9 20.1 20.0 19.2 10.4 23.5 36.3 6.03 0.672 -#> # ... with 5 more variables: kurtosis , coeff_var , q1 , -#> # q3 , iqrange +#> # ℹ 5 more variables: kurtosis , coeff_var , q1 , q3 , +#> # iqrange ``` ## Features -- Summary statistics -- Two way tables -- One way table -- Group wise summary -- Multiple variable statistics -- Multiple one way tables -- Multiple two way tables +- Summary statistics +- Two way tables +- One way table +- Group wise summary +- Multiple variable statistics +- Multiple one way tables +- Multiple two way tables ## Getting Help diff --git a/man/descriptr.Rd b/man/descriptr.Rd index 844e7b4..3165ac3 100644 --- a/man/descriptr.Rd +++ b/man/descriptr.Rd @@ -3,7 +3,23 @@ \docType{package} \name{descriptr} \alias{descriptr} +\alias{_PACKAGE} +\alias{descriptr-package} \title{\code{descriptr} package} \description{ Generate descriptive statistics and explore statistical distributions } +\seealso{ +Useful links: +\itemize{ + \item \url{https://descriptr.rsquaredacademy.com/} + \item \url{https://github.com/rsquaredacademy/descriptr} + \item Report bugs at \url{https://github.com/rsquaredacademy/descriptr/issues} +} + +} +\author{ +\strong{Maintainer}: Aravind Hebbali \email{hebbali.aravind@gmail.com} (\href{https://orcid.org/0000-0001-9220-9669}{ORCID}) + +} +\keyword{internal} diff --git a/man/ds_summary_stats.Rd b/man/ds_summary_stats.Rd index 00ca3e6..244c382 100644 --- a/man/ds_summary_stats.Rd +++ b/man/ds_summary_stats.Rd @@ -7,7 +7,7 @@ ds_summary_stats(data, ...) } \arguments{ -\item{data}{A \code{data.frame} or \code{tibble}.} +\item{data}{An object of type \code{numeric} or \code{data.frame}.} \item{...}{Column(s) in \code{data}.} } @@ -15,6 +15,9 @@ ds_summary_stats(data, ...) Range of descriptive statistics for continuous data. } \examples{ +# numeric data +ds_summary_stats(mtcarz$mpg) + # single variable ds_summary_stats(mtcarz, mpg) diff --git a/tests/testthat.R b/tests/testthat.R index e4eb624..1249a2a 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(descriptr) diff --git a/tests/testthat/_snaps/auto-summary.md b/tests/testthat/_snaps/auto-summary.md new file mode 100644 index 0000000..d49d12c --- /dev/null +++ b/tests/testthat/_snaps/auto-summary.md @@ -0,0 +1,375 @@ +# output from ds_auto_summary is as expected + + Code + ds_auto_summary_stats(mtcarz, mpg) + Output + -------------------------------- Variable: mpg -------------------------------- + + ------------------------------ Summary Statistics ------------------------------ + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Output + -------------------------------- Variable: mpg -------------------------------- + + Univariate Analysis + + N 32.00 Variance 36.32 + Missing 0.00 Std Deviation 6.03 + Mean 20.09 Range 23.50 + Median 19.20 Interquartile Range 7.38 + Mode 10.40 Uncorrected SS 14042.31 + Trimmed Mean 19.95 Corrected SS 1126.05 + Skewness 0.67 Coeff Variation 30.00 + Kurtosis -0.02 Std Error Mean 1.07 + + Quantiles + + Quantile Value + + Max 33.90 + 99% 33.44 + 95% 31.30 + 90% 30.09 + Q3 22.80 + Median 19.20 + Q1 15.43 + 10% 14.34 + 5% 12.00 + 1% 10.40 + Min 10.40 + + Extreme Values + + Low High + + Obs Value Obs Value + 15 10.4 20 33.9 + 16 10.4 18 32.4 + 24 13.3 19 30.4 + 7 14.3 28 30.4 + 17 14.7 26 27.3 + + + + NULL + + + ---------------------------- Frequency Distribution ---------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Output + Variable: mpg + |-----------------------------------------------------------------------| + | Bins | Frequency | Cum Frequency | Percent | Cum Percent | + |-----------------------------------------------------------------------| + | 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | + |-----------------------------------------------------------------------| + | 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | + |-----------------------------------------------------------------------| + | 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | + |-----------------------------------------------------------------------| + | 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | + |-----------------------------------------------------------------------| + | 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | + |-----------------------------------------------------------------------| + | Total | 32 | - | 100.00 | - | + |-----------------------------------------------------------------------| + + + +--- + + Code + ds_auto_summary_stats(sdata) + Output + -------------------------------- Variable: mpg -------------------------------- + + ------------------------------ Summary Statistics ------------------------------ + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Output + -------------------------------- Variable: mpg -------------------------------- + + Univariate Analysis + + N 32.00 Variance 36.32 + Missing 0.00 Std Deviation 6.03 + Mean 20.09 Range 23.50 + Median 19.20 Interquartile Range 7.38 + Mode 10.40 Uncorrected SS 14042.31 + Trimmed Mean 19.95 Corrected SS 1126.05 + Skewness 0.67 Coeff Variation 30.00 + Kurtosis -0.02 Std Error Mean 1.07 + + Quantiles + + Quantile Value + + Max 33.90 + 99% 33.44 + 95% 31.30 + 90% 30.09 + Q3 22.80 + Median 19.20 + Q1 15.43 + 10% 14.34 + 5% 12.00 + 1% 10.40 + Min 10.40 + + Extreme Values + + Low High + + Obs Value Obs Value + 15 10.4 20 33.9 + 16 10.4 18 32.4 + 24 13.3 19 30.4 + 7 14.3 28 30.4 + 17 14.7 26 27.3 + + + + NULL + + + ---------------------------- Frequency Distribution ---------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(i) + + # Now: + data %>% select(all_of(i)) + + See . + Output + Variable: mpg + |-----------------------------------------------------------------------| + | Bins | Frequency | Cum Frequency | Percent | Cum Percent | + |-----------------------------------------------------------------------| + | 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | + |-----------------------------------------------------------------------| + | 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | + |-----------------------------------------------------------------------| + | 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | + |-----------------------------------------------------------------------| + | 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | + |-----------------------------------------------------------------------| + | 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | + |-----------------------------------------------------------------------| + | Total | 32 | - | 100.00 | - | + |-----------------------------------------------------------------------| + + + +# output from ds_auto_group_summary is as expected + + Code + ds_auto_group_summary(mtcarz, cyl, mpg) + Output + by + ----------------------------------------------------------------------------------------- + | Statistic/Levels| 4| 6| 8| + ----------------------------------------------------------------------------------------- + | Obs| 11| 7| 14| + | Minimum| 21.4| 17.8| 10.4| + | Maximum| 33.9| 21.4| 19.2| + | Mean| 26.66| 19.74| 15.1| + | Median| 26| 19.7| 15.2| + | Mode| 22.8| 21| 10.4| + | Std. Deviation| 4.51| 1.45| 2.56| + | Variance| 20.34| 2.11| 6.55| + | Skewness| 0.35| -0.26| -0.46| + | Kurtosis| -1.43| -1.83| 0.33| + | Uncorrected SS| 8023.83| 2741.14| 3277.34| + | Corrected SS| 203.39| 12.68| 85.2| + | Coeff Variation| 16.91| 7.36| 16.95| + | Std. Error Mean| 1.36| 0.55| 0.68| + | Range| 12.5| 3.6| 8.8| + | Interquartile Range| 7.6| 2.35| 1.85| + ----------------------------------------------------------------------------------------- + + + + +--- + + Code + ds_auto_group_summary(gdata) + Output + by + ----------------------------------------------------------------------------------------- + | Statistic/Levels| 4| 6| 8| + ----------------------------------------------------------------------------------------- + | Obs| 11| 7| 14| + | Minimum| 21.4| 17.8| 10.4| + | Maximum| 33.9| 21.4| 19.2| + | Mean| 26.66| 19.74| 15.1| + | Median| 26| 19.7| 15.2| + | Mode| 22.8| 21| 10.4| + | Std. Deviation| 4.51| 1.45| 2.56| + | Variance| 20.34| 2.11| 6.55| + | Skewness| 0.35| -0.26| -0.46| + | Kurtosis| -1.43| -1.83| 0.33| + | Uncorrected SS| 8023.83| 2741.14| 3277.34| + | Corrected SS| 203.39| 12.68| 85.2| + | Coeff Variation| 16.91| 7.36| 16.95| + | Std. Error Mean| 1.36| 0.55| 0.68| + | Range| 12.5| 3.6| 8.8| + | Interquartile Range| 7.6| 2.35| 1.85| + ----------------------------------------------------------------------------------------- + + + + +# output from ds_auto_cross_table is as expected + + Code + ds_auto_cross_table(mtcarz, cyl, gear) + Output + Cell Contents + |---------------| + | Frequency | + | Percent | + | Row Pct | + | Col Pct | + |---------------| + + Total Observations: 32 + + cyl vs gear + ---------------------------------------------------------------------------- + | | gear | + ---------------------------------------------------------------------------- + | cyl | 3 | 4 | 5 | Row Total | + ---------------------------------------------------------------------------- + | 4 | 1 | 8 | 2 | 11 | + | | 0.031 | 0.25 | 0.062 | | + | | 0.09 | 0.73 | 0.18 | 0.34 | + | | 0.07 | 0.67 | 0.4 | | + ---------------------------------------------------------------------------- + | 6 | 2 | 4 | 1 | 7 | + | | 0.062 | 0.125 | 0.031 | | + | | 0.29 | 0.57 | 0.14 | 0.22 | + | | 0.13 | 0.33 | 0.2 | | + ---------------------------------------------------------------------------- + | 8 | 12 | 0 | 2 | 14 | + | | 0.375 | 0 | 0.062 | | + | | 0.86 | 0 | 0.14 | 0.44 | + | | 0.8 | 0 | 0.4 | | + ---------------------------------------------------------------------------- + | Column Total | 15 | 12 | 5 | 32 | + | | 0.468 | 0.375 | 0.155 | | + ---------------------------------------------------------------------------- + + + +# output from ds_auto_freq_table is as expected + + Code + ds_auto_freq_table(mtcarz, cyl, gear) + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: cyl + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 4 11 11 34.38 34.38 + ----------------------------------------------------------------------- + 6 7 18 21.88 56.25 + ----------------------------------------------------------------------- + 8 14 32 43.75 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: gear + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 3 15 15 46.88 46.88 + ----------------------------------------------------------------------- + 4 12 27 37.5 84.38 + ----------------------------------------------------------------------- + 5 5 32 15.62 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + diff --git a/tests/testthat/_snaps/cross-table.md b/tests/testthat/_snaps/cross-table.md new file mode 100644 index 0000000..7271604 --- /dev/null +++ b/tests/testthat/_snaps/cross-table.md @@ -0,0 +1,39 @@ +# output from ds_cross_table is as expected + + Code + ds_cross_table(mtcarz, cyl, gear) + Output + Cell Contents + |---------------| + | Frequency | + | Percent | + | Row Pct | + | Col Pct | + |---------------| + + Total Observations: 32 + + ---------------------------------------------------------------------------- + | | gear | + ---------------------------------------------------------------------------- + | cyl | 3 | 4 | 5 | Row Total | + ---------------------------------------------------------------------------- + | 4 | 1 | 8 | 2 | 11 | + | | 0.031 | 0.25 | 0.062 | | + | | 0.09 | 0.73 | 0.18 | 0.34 | + | | 0.07 | 0.67 | 0.4 | | + ---------------------------------------------------------------------------- + | 6 | 2 | 4 | 1 | 7 | + | | 0.062 | 0.125 | 0.031 | | + | | 0.29 | 0.57 | 0.14 | 0.22 | + | | 0.13 | 0.33 | 0.2 | | + ---------------------------------------------------------------------------- + | 8 | 12 | 0 | 2 | 14 | + | | 0.375 | 0 | 0.062 | | + | | 0.86 | 0 | 0.14 | 0.44 | + | | 0.8 | 0 | 0.4 | | + ---------------------------------------------------------------------------- + | Column Total | 15 | 12 | 5 | 32 | + | | 0.468 | 0.375 | 0.155 | | + ---------------------------------------------------------------------------- + diff --git a/tests/testthat/_snaps/output.md b/tests/testthat/_snaps/output.md new file mode 100644 index 0000000..6baef64 --- /dev/null +++ b/tests/testthat/_snaps/output.md @@ -0,0 +1,456 @@ +# output from print_cross matches expected output + + Code + ds_cross_table(mt, cyl, vs) + Output + Cell Contents + |---------------| + | Frequency | + | Percent | + | Row Pct | + | Col Pct | + |---------------| + + Total Observations: 32 + + ------------------------------------------------------------- + | | vs | + ------------------------------------------------------------- + | cyl | 0 | 1 | Row Total | + ------------------------------------------------------------- + | 4 | 1 | 10 | 11 | + | | 0.031 | 0.312 | | + | | 0.09 | 0.91 | 0.34 | + | | 0.06 | 0.71 | | + ------------------------------------------------------------- + | 6 | 3 | 4 | 7 | + | | 0.094 | 0.125 | | + | | 0.43 | 0.57 | 0.22 | + | | 0.17 | 0.29 | | + ------------------------------------------------------------- + | 8 | 14 | 0 | 14 | + | | 0.438 | 0 | | + | | 1 | 0 | 0.44 | + | | 0.78 | 0 | | + ------------------------------------------------------------- + | Column Total | 18 | 14 | 32 | + | | 0.563 | 0.437 | | + ------------------------------------------------------------- + +# output from print_screener matches expected output + + Code + ds_screener(mt) + Output + ----------------------------------------------------------------------- + | Column Name | Data Type | Levels | Missing | Missing (%) | + ----------------------------------------------------------------------- + | mpg | numeric | NA | 0 | 0 | + | cyl | factor | 4 6 8 | 0 | 0 | + | disp | numeric | NA | 0 | 0 | + | hp | numeric | NA | 0 | 0 | + | drat | numeric | NA | 0 | 0 | + | wt | numeric | NA | 0 | 0 | + | qsec | numeric | NA | 0 | 0 | + | vs | factor | 0 1 | 0 | 0 | + | am | factor | 0 1 | 0 | 0 | + | gear | factor | 3 4 5 | 0 | 0 | + | carb | factor |1 2 3 4 6 8| 0 | 0 | + ----------------------------------------------------------------------- + + Overall Missing Values 0 + Percentage of Missing Values 0 % + Rows with Missing Values 0 + Columns With Missing Values 0 + +# output from print_fcont matches the expected result + + Code + ds_freq_table(mtcars, mpg) + Output + Variable: mpg + |-----------------------------------------------------------------------| + | Bins | Frequency | Cum Frequency | Percent | Cum Percent | + |-----------------------------------------------------------------------| + | 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | + |-----------------------------------------------------------------------| + | 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | + |-----------------------------------------------------------------------| + | 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | + |-----------------------------------------------------------------------| + | 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | + |-----------------------------------------------------------------------| + | 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | + |-----------------------------------------------------------------------| + | Total | 32 | - | 100.00 | - | + |-----------------------------------------------------------------------| + +# output from print_fcont is as expected when data has missing values + + Code + ds_freq_table(mtcars, mpg) + Output + Variable: mpg + |-----------------------------------------------------------------------| + | Bins | Frequency | Cum Frequency | Percent | Cum Percent | + |-----------------------------------------------------------------------| + | 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | + |-----------------------------------------------------------------------| + | 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | + |-----------------------------------------------------------------------| + | 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | + |-----------------------------------------------------------------------| + | 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | + |-----------------------------------------------------------------------| + | 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | + |-----------------------------------------------------------------------| + | Total | 32 | - | 100.00 | - | + |-----------------------------------------------------------------------| + +# output from freq_table matches the expected result + + Code + ds_freq_table(mt, cyl) + Output + Variable: cyl + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 4 11 11 34.38 34.38 + ----------------------------------------------------------------------- + 6 7 18 21.88 56.25 + ----------------------------------------------------------------------- + 8 14 32 43.75 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + +# output from freq_table is as expected when data has missing values + + Code + ds_freq_table(mt, cyl) + Output + Variable: cyl + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 4 9 9 32.14 32.14 + ----------------------------------------------------------------------- + 6 6 15 21.43 53.57 + ----------------------------------------------------------------------- + 8 13 28 46.43 100 + ----------------------------------------------------------------------- + Missing 4 - - + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + +# output from group_summary matches the expected result + + Code + ds_group_summary(mt, cyl, mpg) + Output + by + ----------------------------------------------------------------------------------------- + | Statistic/Levels| 4| 6| 8| + ----------------------------------------------------------------------------------------- + | Obs| 11| 7| 14| + | Minimum| 21.4| 17.8| 10.4| + | Maximum| 33.9| 21.4| 19.2| + | Mean| 26.66| 19.74| 15.1| + | Median| 26| 19.7| 15.2| + | Mode| 22.8| 21| 10.4| + | Std. Deviation| 4.51| 1.45| 2.56| + | Variance| 20.34| 2.11| 6.55| + | Skewness| 0.35| -0.26| -0.46| + | Kurtosis| -1.43| -1.83| 0.33| + | Uncorrected SS| 8023.83| 2741.14| 3277.34| + | Corrected SS| 203.39| 12.68| 85.2| + | Coeff Variation| 16.91| 7.36| 16.95| + | Std. Error Mean| 1.36| 0.55| 0.68| + | Range| 12.5| 3.6| 8.8| + | Interquartile Range| 7.6| 2.35| 1.85| + ----------------------------------------------------------------------------------------- + +# output from print_ftable2 matches the expected result + + Code + ds_auto_freq_table(mt) + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: cyl + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 4 11 11 34.38 34.38 + ----------------------------------------------------------------------- + 6 7 18 21.88 56.25 + ----------------------------------------------------------------------- + 8 14 32 43.75 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: vs + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 0 18 18 56.25 56.25 + ----------------------------------------------------------------------- + 1 14 32 43.75 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: am + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 0 19 19 59.38 59.38 + ----------------------------------------------------------------------- + 1 13 32 40.62 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: gear + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 3 15 15 46.88 46.88 + ----------------------------------------------------------------------- + 4 12 27 37.5 84.38 + ----------------------------------------------------------------------- + 5 5 32 15.62 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: carb + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 1 7 7 21.88 21.88 + ----------------------------------------------------------------------- + 2 10 17 31.25 53.12 + ----------------------------------------------------------------------- + 3 3 20 9.38 62.5 + ----------------------------------------------------------------------- + 4 10 30 31.25 93.75 + ----------------------------------------------------------------------- + 6 1 31 3.12 96.88 + ----------------------------------------------------------------------- + 8 1 32 3.12 100 + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + +# output from ds_auto_freq_table() is as expected when data has missing values + + Code + ds_auto_freq_table(fdata) + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: cyl + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 4 9 9 32.14 32.14 + ----------------------------------------------------------------------- + 6 6 15 21.43 53.57 + ----------------------------------------------------------------------- + 8 13 28 46.43 100 + ----------------------------------------------------------------------- + Missing 4 - 12.50 - + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + Condition + Warning: + Using an external vector in selections was deprecated in tidyselect 1.1.0. + i Please use `all_of()` or `any_of()` instead. + # Was: + data %>% select(name) + + # Now: + data %>% select(all_of(name)) + + See . + Output + Variable: gear + ----------------------------------------------------------------------- + Levels Frequency Cum Frequency Percent Cum Percent + ----------------------------------------------------------------------- + 3 13 13 46.43 46.43 + ----------------------------------------------------------------------- + 4 10 23 35.71 82.14 + ----------------------------------------------------------------------- + 5 5 28 17.86 100 + ----------------------------------------------------------------------- + Missing 4 - 12.50 - + ----------------------------------------------------------------------- + Total 32 - 100.00 - + ----------------------------------------------------------------------- + + +# output from print_cross2 matches the expected result + + Code + ds_auto_cross_table(mt) + Output + Cell Contents + |---------------| + | Frequency | + | Percent | + | Row Pct | + | Col Pct | + |---------------| + + Total Observations: 32 + + cyl vs vs + ------------------------------------------------------------- + | | vs | + ------------------------------------------------------------- + | cyl | 0 | 1 | Row Total | + ------------------------------------------------------------- + | 4 | 1 | 10 | 11 | + | | 0.031 | 0.312 | | + | | 0.09 | 0.91 | 0.34 | + | | 0.06 | 0.71 | | + ------------------------------------------------------------- + | 6 | 3 | 4 | 7 | + | | 0.094 | 0.125 | | + | | 0.43 | 0.57 | 0.22 | + | | 0.17 | 0.29 | | + ------------------------------------------------------------- + | 8 | 14 | 0 | 14 | + | | 0.438 | 0 | | + | | 1 | 0 | 0.44 | + | | 0.78 | 0 | | + ------------------------------------------------------------- + | Column Total | 18 | 14 | 32 | + | | 0.563 | 0.437 | | + ------------------------------------------------------------- + + + cyl vs am + ------------------------------------------------------------- + | | am | + ------------------------------------------------------------- + | cyl | 0 | 1 | Row Total | + ------------------------------------------------------------- + | 4 | 3 | 8 | 11 | + | | 0.094 | 0.25 | | + | | 0.27 | 0.73 | 0.34 | + | | 0.16 | 0.62 | | + ------------------------------------------------------------- + | 6 | 4 | 3 | 7 | + | | 0.125 | 0.094 | | + | | 0.57 | 0.43 | 0.22 | + | | 0.21 | 0.23 | | + ------------------------------------------------------------- + | 8 | 12 | 2 | 14 | + | | 0.375 | 0.062 | | + | | 0.86 | 0.14 | 0.44 | + | | 0.63 | 0.15 | | + ------------------------------------------------------------- + | Column Total | 19 | 13 | 32 | + | | 0.594 | 0.406 | | + ------------------------------------------------------------- + + + vs vs am + ------------------------------------------------------------- + | | am | + ------------------------------------------------------------- + | vs | 0 | 1 | Row Total | + ------------------------------------------------------------- + | 0 | 12 | 6 | 18 | + | | 0.375 | 0.188 | | + | | 0.67 | 0.33 | 0.56 | + | | 0.63 | 0.46 | | + ------------------------------------------------------------- + | 1 | 7 | 7 | 14 | + | | 0.219 | 0.219 | | + | | 0.5 | 0.5 | 0.44 | + | | 0.37 | 0.54 | | + ------------------------------------------------------------- + | Column Total | 19 | 13 | 32 | + | | 0.594 | 0.407 | | + ------------------------------------------------------------- + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-1.svg b/tests/testthat/_snaps/plots/ds-plot-bar-1.svg index 80eac9f..648925d 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-1.svg @@ -27,9 +27,9 @@ - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-2.svg b/tests/testthat/_snaps/plots/ds-plot-bar-2.svg index 68ded50..7871dd2 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-2.svg @@ -27,9 +27,9 @@ - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-3.svg b/tests/testthat/_snaps/plots/ds-plot-bar-3.svg index b1be80f..9e4a6ed 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-3.svg @@ -27,9 +27,9 @@ - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-4.svg b/tests/testthat/_snaps/plots/ds-plot-bar-4.svg index 2fe22c7..5245a53 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-4.svg @@ -27,9 +27,9 @@ - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-1.svg b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-1.svg index 3b0c491..25031c7 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-1.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -61,11 +61,11 @@ gear - + - + - + 3 4 5 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-2.svg b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-2.svg index c4bce56..9f9d354 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-2.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -61,11 +61,11 @@ cyl - + - + - + 4 6 8 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-3.svg b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-3.svg index 71c8795..f3ef1ab 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-3.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -61,11 +61,11 @@ gear - + - + - + 3 4 5 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-4.svg b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-4.svg index 72ba9d7..2366ead 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-grouped-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-grouped-4.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -61,11 +61,11 @@ cyl - + - + - + 4 6 8 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-1.svg b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-1.svg index 06864de..e685d8e 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-1.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -55,11 +55,11 @@ gear - + - + - + 3 4 5 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-2.svg b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-2.svg index c1c39df..97b7728 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-2.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -57,11 +57,11 @@ cyl - + - + - + 4 6 8 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-3.svg b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-3.svg index 0a18d4e..d33b352 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-3.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -55,11 +55,11 @@ gear - + - + - + 3 4 5 diff --git a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-4.svg b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-4.svg index a06a663..eae12f1 100644 --- a/tests/testthat/_snaps/plots/ds-plot-bar-stacked-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-bar-stacked-4.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + @@ -57,11 +57,11 @@ cyl - + - + - + 4 6 8 diff --git a/tests/testthat/_snaps/plots/ds-plot-box-group-1.svg b/tests/testthat/_snaps/plots/ds-plot-box-group-1.svg index 982a459..b5793fc 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-group-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-group-1.svg @@ -29,19 +29,19 @@ - - + + - - + + - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-group-2.svg b/tests/testthat/_snaps/plots/ds-plot-box-group-2.svg index 9c77d27..2c377d1 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-group-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-group-2.svg @@ -29,16 +29,16 @@ - - + + - - + + - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-group-3.svg b/tests/testthat/_snaps/plots/ds-plot-box-group-3.svg index ee0f142..c97b405 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-group-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-group-3.svg @@ -29,19 +29,19 @@ - - + + - - + + - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-single-1.svg b/tests/testthat/_snaps/plots/ds-plot-box-single-1.svg index 6419e1e..4c612e0 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-single-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-single-1.svg @@ -30,8 +30,8 @@ - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-single-2.svg b/tests/testthat/_snaps/plots/ds-plot-box-single-2.svg index a155c51..05b3746 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-single-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-single-2.svg @@ -29,8 +29,8 @@ - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-single-3.svg b/tests/testthat/_snaps/plots/ds-plot-box-single-3.svg index 1bc1882..32799b8 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-single-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-single-3.svg @@ -30,8 +30,8 @@ - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-box-single-4.svg b/tests/testthat/_snaps/plots/ds-plot-box-single-4.svg index 2bba5b5..aa53b47 100644 --- a/tests/testthat/_snaps/plots/ds-plot-box-single-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-box-single-4.svg @@ -29,8 +29,8 @@ - - + + diff --git a/tests/testthat/_snaps/plots/ds-plot-density-1.svg b/tests/testthat/_snaps/plots/ds-plot-density-1.svg index 8080cfe..a363d20 100644 --- a/tests/testthat/_snaps/plots/ds-plot-density-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-density-1.svg @@ -27,19 +27,19 @@ - - + + 0.00 -0.02 -0.04 -0.06 +0.02 +0.04 +0.06 - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-density-2.svg b/tests/testthat/_snaps/plots/ds-plot-density-2.svg index 1a049be..3d3da17 100644 --- a/tests/testthat/_snaps/plots/ds-plot-density-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-density-2.svg @@ -27,19 +27,19 @@ - - + + 0.000 -0.001 -0.002 -0.003 +0.001 +0.002 +0.003 - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-density-3.svg b/tests/testthat/_snaps/plots/ds-plot-density-3.svg index 8c955ff..e6f6e77 100644 --- a/tests/testthat/_snaps/plots/ds-plot-density-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-density-3.svg @@ -27,19 +27,19 @@ - - + + 0.000 -0.002 -0.004 -0.006 +0.002 +0.004 +0.006 - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-density-4.svg b/tests/testthat/_snaps/plots/ds-plot-density-4.svg index a5121f0..452e8b4 100644 --- a/tests/testthat/_snaps/plots/ds-plot-density-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-density-4.svg @@ -27,19 +27,19 @@ - - + + 0.00 -0.02 -0.04 -0.06 +0.02 +0.04 +0.06 - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-density-5.svg b/tests/testthat/_snaps/plots/ds-plot-density-5.svg index 60e007e..4ea2bd1 100644 --- a/tests/testthat/_snaps/plots/ds-plot-density-5.svg +++ b/tests/testthat/_snaps/plots/ds-plot-density-5.svg @@ -27,19 +27,19 @@ - - + + 0.000 -0.001 -0.002 -0.003 +0.001 +0.002 +0.003 - - - + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-hist-1.svg b/tests/testthat/_snaps/plots/ds-plot-hist-1.svg index b2d664c..2c5968f 100644 --- a/tests/testthat/_snaps/plots/ds-plot-hist-1.svg +++ b/tests/testthat/_snaps/plots/ds-plot-hist-1.svg @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-hist-2.svg b/tests/testthat/_snaps/plots/ds-plot-hist-2.svg index 4d8f455..a08453b 100644 --- a/tests/testthat/_snaps/plots/ds-plot-hist-2.svg +++ b/tests/testthat/_snaps/plots/ds-plot-hist-2.svg @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-hist-3.svg b/tests/testthat/_snaps/plots/ds-plot-hist-3.svg index 2378bad..31ef646 100644 --- a/tests/testthat/_snaps/plots/ds-plot-hist-3.svg +++ b/tests/testthat/_snaps/plots/ds-plot-hist-3.svg @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-hist-4.svg b/tests/testthat/_snaps/plots/ds-plot-hist-4.svg index bee45a2..30a6dee 100644 --- a/tests/testthat/_snaps/plots/ds-plot-hist-4.svg +++ b/tests/testthat/_snaps/plots/ds-plot-hist-4.svg @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/tests/testthat/_snaps/plots/ds-plot-hist-5.svg b/tests/testthat/_snaps/plots/ds-plot-hist-5.svg index b38f687..5bdc356 100644 --- a/tests/testthat/_snaps/plots/ds-plot-hist-5.svg +++ b/tests/testthat/_snaps/plots/ds-plot-hist-5.svg @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/tests/testthat/_snaps/plots/ds-screener-1.svg b/tests/testthat/_snaps/plots/ds-screener-1.svg index 6134866..e68ce04 100644 --- a/tests/testthat/_snaps/plots/ds-screener-1.svg +++ b/tests/testthat/_snaps/plots/ds-screener-1.svg @@ -21,55 +21,55 @@ - - + + - - - - - - - - - + + + + + + + + + -0.0% -5.0% -10.0% -15.0% -20.0% -25.0% - - - - - - - - - - - - -Day -Month -Temp -Wind -Solar.R -Ozone -Column +0% +5% +10% +15% +20% +25% + + + + + + + + + + + + +Day +Month +Temp +Wind +Solar.R +Ozone +Column Percentage % Missing - + - + < 10% >= 10% -Missing Values (%) +Missing Values (%) diff --git a/tests/testthat/test-auto-summary.R b/tests/testthat/test-auto-summary.R index 2bac129..3b1c2ea 100644 --- a/tests/testthat/test-auto-summary.R +++ b/tests/testthat/test-auto-summary.R @@ -1,5 +1,3 @@ -context("test-auto-summary") - ndata <- dplyr::select(mtcarz, mpg, disp, hp, wt, qsec, drat) fdata <- dplyr::select(mtcarz, cyl, gear, am, vs) sdata <- dplyr::select(mtcarz, mpg) @@ -30,178 +28,20 @@ test_that("ds_auto_cross_table throws errors as expected", { }) test_that("output from ds_auto_summary is as expected", { - pim <- "--------------------------- Variable: mpg -------------------------- - ------------------------- Summary Statistics ------------------------ - - Univariate Analysis - - N 32.00 Variance 36.32 - Missing 0.00 Std Deviation 6.03 - Mean 20.09 Range 23.50 - Median 19.20 Interquartile Range 7.38 - Mode 10.40 Uncorrected SS 14042.31 - Trimmed Mean 19.95 Corrected SS 1126.05 - Skewness 0.67 Coeff Variation 30.00 - Kurtosis -0.02 Std Error Mean 1.07 - - Quantiles - - Quantile Value - - Max 33.90 - 99% 33.44 - 95% 31.30 - 90% 30.09 - Q3 22.80 - Median 19.20 - Q1 15.43 - 10% 14.34 - 5% 12.00 - 1% 10.40 - Min 10.40 - - Extreme Values - - Low High - - Obs Value Obs Value - 15 10.4 20 33.9 - 16 10.4 18 32.4 - 24 13.3 19 30.4 - 7 14.3 28 30.4 - 17 14.7 26 27.3 - - ----------------------- Frequency Distribution ---------------------- - - Variable: mpg -|-----------------------------------------------------------------------| -| Bins | Frequency | Cum Frequency | Percent | Cum Percent | -|-----------------------------------------------------------------------| -| 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | -|-----------------------------------------------------------------------| -| 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | -|-----------------------------------------------------------------------| -| 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | -|-----------------------------------------------------------------------| -| 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | -|-----------------------------------------------------------------------| -| 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | -|-----------------------------------------------------------------------| -| Total | 32 | - | 100.00 | - | -|-----------------------------------------------------------------------| - - -" -expect_output(ds_auto_summary_stats(mtcarz, mpg), pim) -expect_output(ds_auto_summary_stats(sdata), pim) + expect_snapshot(ds_auto_summary_stats(mtcarz, mpg)) + expect_snapshot(ds_auto_summary_stats(sdata)) }) test_that("output from ds_auto_group_summary is as expected", { - pim <- " mpg by cyl ------------------------------------------------------------------------------------------ -| Statistic/Levels| 4| 6| 8| ------------------------------------------------------------------------------------------ -| Obs| 11| 7| 14| -| Minimum| 21.4| 17.8| 10.4| -| Maximum| 33.9| 21.4| 19.2| -| Mean| 26.66| 19.74| 15.1| -| Median| 26| 19.7| 15.2| -| Mode| 22.8| 21| 10.4| -| Std. Deviation| 4.51| 1.45| 2.56| -| Variance| 20.34| 2.11| 6.55| -| Skewness| 0.35| -0.26| -0.46| -| Kurtosis| -1.43| -1.83| 0.33| -| Uncorrected SS| 8023.83| 2741.14| 3277.34| -| Corrected SS| 203.39| 12.68| 85.2| -| Coeff Variation| 16.91| 7.36| 16.95| -| Std. Error Mean| 1.36| 0.55| 0.68| -| Range| 12.5| 3.6| 8.8| -| Interquartile Range| 7.6| 2.35| 1.85| ------------------------------------------------------------------------------------------ - - - -" - -expect_output(ds_auto_group_summary(mtcarz, cyl, mpg), pim) -expect_output(ds_auto_group_summary(gdata), pim) + expect_snapshot(ds_auto_group_summary(mtcarz, cyl, mpg)) + expect_snapshot(ds_auto_group_summary(gdata)) }) test_that("output from ds_auto_cross_table is as expected", { - - pim <- " Cell Contents - |---------------| - | Frequency | - | Percent | - | Row Pct | - | Col Pct | - |---------------| - - Total Observations: 32 - - cyl vs gear ----------------------------------------------------------------------------- -| | gear | ----------------------------------------------------------------------------- -| cyl | 3 | 4 | 5 | Row Total | ----------------------------------------------------------------------------- -| 4 | 1 | 8 | 2 | 11 | -| | 0.031 | 0.25 | 0.062 | | -| | 0.09 | 0.73 | 0.18 | 0.34 | -| | 0.07 | 0.67 | 0.4 | | ----------------------------------------------------------------------------- -| 6 | 2 | 4 | 1 | 7 | -| | 0.062 | 0.125 | 0.031 | | -| | 0.29 | 0.57 | 0.14 | 0.22 | -| | 0.13 | 0.33 | 0.2 | | ----------------------------------------------------------------------------- -| 8 | 12 | 0 | 2 | 14 | -| | 0.375 | 0 | 0.062 | | -| | 0.86 | 0 | 0.14 | 0.44 | -| | 0.8 | 0 | 0.4 | | ----------------------------------------------------------------------------- -| Column Total | 15 | 12 | 5 | 32 | -| | 0.468 | 0.375 | 0.155 | | ----------------------------------------------------------------------------- - - -" - -expect_output(ds_auto_cross_table(mtcarz, cyl, gear), pim) - + expect_snapshot(ds_auto_cross_table(mtcarz, cyl, gear)) }) test_that("output from ds_auto_freq_table is as expected", { - - pim <- " Variable: cyl ------------------------------------------------------------------------ -Levels Frequency Cum Frequency Percent Cum Percent ------------------------------------------------------------------------ - 4 11 11 34.38 34.38 ------------------------------------------------------------------------ - 6 7 18 21.88 56.25 ------------------------------------------------------------------------ - 8 14 32 43.75 100 ------------------------------------------------------------------------ - Total 32 - 100.00 - ------------------------------------------------------------------------ - - Variable: gear ------------------------------------------------------------------------ -Levels Frequency Cum Frequency Percent Cum Percent ------------------------------------------------------------------------ - 3 15 15 46.88 46.88 ------------------------------------------------------------------------ - 4 12 27 37.5 84.38 ------------------------------------------------------------------------ - 5 5 32 15.62 100 ------------------------------------------------------------------------ - Total 32 - 100.00 - ------------------------------------------------------------------------" - -expect_output(ds_auto_freq_table(mtcarz, cyl, gear), pim) - -}) \ No newline at end of file + expect_snapshot(ds_auto_freq_table(mtcarz, cyl, gear)) +}) diff --git a/tests/testthat/test-cross-table.R b/tests/testthat/test-cross-table.R index 4efba9a..33055e3 100644 --- a/tests/testthat/test-cross-table.R +++ b/tests/testthat/test-cross-table.R @@ -1,49 +1,47 @@ -context("ds_cross_table") - test_that("output from ds_cross_table matches expected results", { k <- ds_cross_table(hsb, ses, female) expect_equal(k$utility$obs, 200) - expect_equivalent(k$utility$var2_levels, c("0", "1")) + expect_equal(k$utility$var2_levels, c("0", "1")) - expect_equivalent(k$utility$var1_levels, c("1", "2", "3")) + expect_equal(k$utility$var1_levels, c("1", "2", "3")) - expect_equivalent(k$utility$varnames, c("ses", "female")) + expect_equal(k$utility$varnames, c("ses", "female")) - expect_equivalent(k$utility$twowaytable[, 1], c("1", "2", "3")) + expect_equal(k$utility$twowaytable[, 1], c("1", "2", "3")) - expect_equivalent(k$utility$twowaytable[, 2], c("15", "47", "29")) + expect_equal(k$utility$twowaytable[, 2], c("15", "47", "29")) - expect_equivalent(k$utility$twowaytable[, 3], c("32", "48", "29")) + expect_equal(k$utility$twowaytable[, 3], c("32", "48", "29")) - expect_equivalent(k$utility$twowaytable[, 4], c("47", "95", "58")) + expect_equal(k$utility$twowaytable[, 4], c("47", "95", "58")) - expect_equivalent(colnames(k$utility$twowaytable), c("", "0", "1", "rowtotal")) + expect_equal(colnames(k$utility$twowaytable), c("", "0", "1", "rowtotal")) - expect_equivalent(k$utility$percent_table[, 1], c(0.075, 0.235, 0.145, 0.455)) + expect_equal(k$utility$percent_table[, 1], c(0.075, 0.235, 0.145, 0.455), ignore_attr = TRUE) - expect_equivalent(k$utility$percent_table[, 2], c(0.160, 0.240, 0.145, 0.545)) + expect_equal(k$utility$percent_table[, 2], c(0.160, 0.240, 0.145, 0.545), ignore_attr = TRUE) - expect_equivalent(k$utility$percent_table[, 3], c(0.235, 0.475, 0.290, 1.000)) + expect_equal(k$utility$percent_table[, 3], c(0.235, 0.475, 0.290, 1.000), ignore_attr = TRUE) - expect_equivalent(colnames(k$utility$percent_table), c("0", "1", "row_pct")) + expect_equal(colnames(k$utility$percent_table), c("0", "1", "row_pct")) - expect_equivalent(rownames(k$utility$percent_table), c("", "", "", "col_pct")) + expect_equal(rownames(k$utility$percent_table), c("", "", "", "col_pct")) - expect_equivalent(k$utility$row_percent[, 1], c(0.32, 0.49, 0.50)) + expect_equal(k$utility$row_percent[, 1], c(0.32, 0.49, 0.50)) - expect_equivalent(k$utility$row_percent[, 2], c(0.68, 0.51, 0.50)) + expect_equal(k$utility$row_percent[, 2], c(0.68, 0.51, 0.50)) - expect_equivalent(k$utility$row_percent[3, 3], c(0.29)) + expect_equal(k$utility$row_percent[3, 3], c(0.29), ignore_attr = TRUE) - expect_equivalent(k$utility$column_percent[, 1], c(0.16, 0.52, 0.32)) + expect_equal(k$utility$column_percent[, 1], c(0.16, 0.52, 0.32)) - expect_equivalent(k$utility$column_percent[, 2], c(0.29, 0.44, 0.27)) + expect_equal(k$utility$column_percent[, 2], c(0.29, 0.44, 0.27)) - expect_equivalent(unname(k$utility$column_totals), c(91, 109)) + expect_equal(unname(k$utility$column_totals), c(91, 109)) - expect_equivalent(unname(k$utility$percent_column), c(0.455, 0.545)) + expect_equal(unname(k$utility$percent_column), c(0.455, 0.545)) }) @@ -55,15 +53,15 @@ test_that("ouput from plot.ds_cross_table matches expected output", { # bar plot p1 <- plot(k) - expect_doppelganger("cross_bar", p1$plot) + vdiffr::expect_doppelganger("cross_bar", p1$plot) # stacked bar plot p2 <- plot(k, stacked = TRUE) - expect_doppelganger("cross_bar_stacked", p2$plot) + vdiffr::expect_doppelganger("cross_bar_stacked", p2$plot) # proportional bar plot p3 <- plot(k, proportional = TRUE) - expect_doppelganger("cross_bar_proportional", p3$plot) + vdiffr::expect_doppelganger("cross_bar_proportional", p3$plot) }) test_that("ds_cross_table throws appropriate error", { @@ -92,43 +90,7 @@ test_that("ds_twoway_table throws appropriate error", { test_that("output from ds_cross_table is as expected", { - - pim <- " Cell Contents - |---------------| - | Frequency | - | Percent | - | Row Pct | - | Col Pct | - |---------------| - - Total Observations: 32 - ----------------------------------------------------------------------------- -| | gear | ----------------------------------------------------------------------------- -| cyl | 3 | 4 | 5 | Row Total | ----------------------------------------------------------------------------- -| 4 | 1 | 8 | 2 | 11 | -| | 0.031 | 0.25 | 0.062 | | -| | 0.09 | 0.73 | 0.18 | 0.34 | -| | 0.07 | 0.67 | 0.4 | | ----------------------------------------------------------------------------- -| 6 | 2 | 4 | 1 | 7 | -| | 0.062 | 0.125 | 0.031 | | -| | 0.29 | 0.57 | 0.14 | 0.22 | -| | 0.13 | 0.33 | 0.2 | | ----------------------------------------------------------------------------- -| 8 | 12 | 0 | 2 | 14 | -| | 0.375 | 0 | 0.062 | | -| | 0.86 | 0 | 0.14 | 0.44 | -| | 0.8 | 0 | 0.4 | | ----------------------------------------------------------------------------- -| Column Total | 15 | 12 | 5 | 32 | -| | 0.468 | 0.375 | 0.155 | | -----------------------------------------------------------------------------" - -expect_output(print(ds_cross_table(mtcarz, cyl, gear)), pim) - + expect_snapshot(ds_cross_table(mtcarz, cyl, gear)) }) test_that("get_names works as expected", { @@ -139,4 +101,4 @@ test_that("get_names works as expected", { expected <- c("3", "4", "5") expect_equal(actual, expected) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-describe.R b/tests/testthat/test-describe.R index 3e59303..582c8c3 100644 --- a/tests/testthat/test-describe.R +++ b/tests/testthat/test-describe.R @@ -1,10 +1,8 @@ -context("describe") - fdata <- dplyr::select(mtcarz, cyl, gear, am, vs) test_that("output from ds_tailobs match expected result", { - expect_equivalent(ds_tailobs(mtcars$mpg, 5, "low"), c(10.4, 10.4, 13.3, 14.3, 14.7)) - expect_equivalent(ds_tailobs(mtcars$mpg, 5, "high"), c(33.9, 32.4, 30.4, 30.4, 27.3)) + expect_equal(ds_tailobs(mtcars$mpg, 5, "low"), c(10.4, 10.4, 13.3, 14.3, 14.7), ignore_attr = TRUE) + expect_equal(ds_tailobs(mtcars$mpg, 5, "high"), c(33.9, 32.4, 30.4, 30.4, 27.3), ignore_attr = TRUE) }) @@ -24,9 +22,9 @@ test_that("ds_tailobs returns the appropriate error", { test_that("output from ds_rindex match expected result", { - expect_equivalent(ds_rindex(mtcars$mpg, c(13.3)), 24) - expect_equivalent(ds_rindex(mtcars$mpg, c(33.9)), 20) - expect_equivalent(ds_rindex(mtcars$mpg, c(13.3, 10.4)), c(24, 15, 16)) + expect_equal(ds_rindex(mtcars$mpg, c(13.3)), 24, ignore_attr = TRUE) + expect_equal(ds_rindex(mtcars$mpg, c(33.9)), 20, ignore_attr = TRUE) + expect_equal(ds_rindex(mtcars$mpg, c(13.3, 10.4)), c(24, 15, 16), ignore_attr = TRUE) expect_null(ds_rindex(mtcars$mpg, c(34))) }) diff --git a/tests/testthat/test-freq-table.R b/tests/testthat/test-freq-table.R index 2ad17df..73f2809 100644 --- a/tests/testthat/test-freq-table.R +++ b/tests/testthat/test-freq-table.R @@ -1,13 +1,11 @@ -context("freq_table") - test_that("output from ds_freq_table matches expected results", { k <- ds_freq_table(mtcarz, cyl) - expect_equivalent(k$ftable[[1]], c("4", "6", "8")) - expect_equivalent(k$ftable[[2]], c(11, 7, 14)) - expect_equivalent(k$ftable[[3]], c(11, 18, 32)) - expect_equivalent(k$ftable[[4]][-2], c(34.38, 43.75)) - expect_equivalent(k$ftable[[5]], c(34.38, 56.25, 100.00)) - expect_equivalent(k$utility$varname, "cyl") + expect_equal(k$ftable[[1]], c("4", "6", "8")) + expect_equal(k$ftable[[2]], c(11, 7, 14)) + expect_equal(k$ftable[[3]], c(11, 18, 32)) + expect_equal(k$ftable[[4]][-2], c(34.38, 43.75)) + expect_equal(k$ftable[[5]], c(34.38, 56.25, 100.00)) + expect_equal(k$utility$varname, "cyl") }) @@ -16,19 +14,19 @@ test_that("output from ds_freq_table plot is as expected", { k <- ds_freq_table(mtcarz, cyl) p <- plot(k) - expect_doppelganger("ds_freq_bar", p$plot) + vdiffr::expect_doppelganger("ds_freq_bar", p$plot) }) test_that("output from ds_freq_cont matches expected result", { k <- ds_freq_table(mtcars, mpg, bins = 4) - expect_equivalent(k$utility$breaks, c(10.400, 16.275, 22.150, 28.025, 33.900)) - expect_equivalent(k$utility$frequency, c(10, 13, 5, 4)) - expect_equivalent(k$utility$cumulative, c(10, 23, 28, 32)) - expect_equivalent(k$utility$percent[-c(2, 3)], c(31.25, 12.50)) - expect_equivalent(k$utility$cum_percent[-2], c(31.25, 87.50, 100.00)) + expect_equal(k$utility$breaks, c(10.400, 16.275, 22.150, 28.025, 33.900)) + expect_equal(k$utility$frequency, c(10, 13, 5, 4)) + expect_equal(k$utility$cumulative, c(10, 23, 28, 32)) + expect_equal(k$utility$percent[-c(2, 3)], c(31.25, 12.50)) + expect_equal(k$utility$cum_percent[-2], c(31.25, 87.50, 100.00)) expect_equal(k$utility$bins, 4) expect_equal(k$utility$data, mtcars$mpg) - expect_equivalent(k$utility$varname, "mpg") + expect_equal(k$utility$varname, "mpg") }) test_that("output from ds_freq_table plot is as expected", { @@ -36,7 +34,7 @@ test_that("output from ds_freq_table plot is as expected", { k <- ds_freq_table(mtcarz, mpg) p <- plot(k) - expect_doppelganger("ds_freq_cont", p$plot) + vdiffr::expect_doppelganger("ds_freq_cont", p$plot) }) test_that("output from ds_freq_table is as expected in the presence of missing data", { @@ -65,4 +63,4 @@ test_that("ds_freq_table throws appropriate error", { expect_error(ds_freq_table(data = mtcarz, col = mpg, bins = "5"), "bins must be integer value") expect_error(ds_freq_table(data = mt, col = gear), "gear is neither continuous nor categorical.") -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-group-summary-interact.R b/tests/testthat/test-group-summary-interact.R index 4c5019f..c94806a 100644 --- a/tests/testthat/test-group-summary-interact.R +++ b/tests/testthat/test-group-summary-interact.R @@ -1,5 +1,3 @@ -context("test-group-summary-interact") - test_that("output from ds_group_summary_interact is as expected", { actual <- ds_group_summary_interact(mtcarz, mpg, cyl, gear) %>% diff --git a/tests/testthat/test-group-summary.R b/tests/testthat/test-group-summary.R index c3eebdc..da4798c 100644 --- a/tests/testthat/test-group-summary.R +++ b/tests/testthat/test-group-summary.R @@ -1,5 +1,3 @@ -context("ds_group_summary") - test_that("output from ds_group_summary matches the expected result", { mt <- mtcars mt$cyl <- as.factor(mt$cyl) @@ -11,18 +9,18 @@ test_that("output from ds_group_summary matches the expected result", { "Std. Error Mean", "Range", "Interquartile Range" ) - expect_equivalent(as.character(k$stats[, 1]), metrics) - expect_equivalent(k$stats[, 2], c( + expect_equal(as.character(k$stats[, 1]), metrics) + expect_equal(k$stats[, 2], c( 11.00, 21.40, 33.90, 26.66, 26.00, 22.80, 4.51, 20.34, 0.35, -1.43, 8023.83, 203.39, 16.91, 1.36, 12.50, 7.60 )) - expect_equivalent(k$stats[, 3], c( + expect_equal(k$stats[, 3], c( 7.00, 17.80, 21.40, 19.74, 19.70, 21.00, 1.45, 2.11, -0.26, -1.83, 2741.14, 12.68, 7.36, 0.55, 3.60, 2.35 )) - expect_equivalent(k$stats[, 4], c( + expect_equal(k$stats[, 4], c( 14.00, 10.40, 19.20, 15.10, 15.20, 10.40, 2.56, 6.55, -0.46, 0.33, 3277.34, 85.20, 16.95, 0.68, 8.80, 1.85 @@ -51,7 +49,7 @@ test_that("output from ds_group_summary plot is as expected", { k <- ds_group_summary(mtcarz, cyl, mpg) p <- plot(k) - expect_doppelganger("group_summary", p$plot) + vdiffr::expect_doppelganger("group_summary", p$plot) }) diff --git a/tests/testthat/test-multistats.R b/tests/testthat/test-multistats.R index caafae0..33de24f 100644 --- a/tests/testthat/test-multistats.R +++ b/tests/testthat/test-multistats.R @@ -1,5 +1,3 @@ -context("multistats") - fdata <- dplyr::select(mtcarz, cyl, gear, am, vs) ndata <- dplyr::select(mtcarz, mpg, disp, hp, wt, qsec, drat) @@ -12,8 +10,9 @@ test_that("output from multistats is as expected", { actual <- ds_tidy_stats(mtcars, mpg, disp, hp) %>% dplyr::filter(vars == "disp") %>% - dplyr::select(min) - expected <- tibble::tibble(min = 71.1) + dplyr::select(min) %>% + as.data.frame() + expected <- data.frame(min = 71.1) expect_equal(actual, expected) diff --git a/tests/testthat/test-output.R b/tests/testthat/test-output.R index 6c1691f..3b6cacc 100644 --- a/tests/testthat/test-output.R +++ b/tests/testthat/test-output.R @@ -1,387 +1,63 @@ -context("print") - mt <- mtcars mt$cyl <- as.factor(mt$cyl) mt$vs <- as.factor(mt$vs) test_that("output from print_cross matches expected output", { - k <- ds_cross_table(mt, cyl, vs) - pim <- " Cell Contents -|---------------| -| Frequency | -| Percent | -| Row Pct | -| Col Pct | -|---------------| -Total Observations: 32 -------------------------------------------------------------- -| | vs | -------------------------------------------------------------- -| cyl | 0 | 1 | Row Total | -------------------------------------------------------------- -| 4 | 1 | 10 | 11 | -| | 0.031 | 0.312 | | -| | 0.09 | 0.91 | 0.34 | -| | 0.06 | 0.71 | | -------------------------------------------------------------- -| 6 | 3 | 4 | 7 | -| | 0.094 | 0.125 | | -| | 0.43 | 0.57 | 0.22 | -| | 0.17 | 0.29 | | -------------------------------------------------------------- -| 8 | 14 | 0 | 14 | -| | 0.438 | 0 | | -| | 1 | 0 | 0.44 | -| | 0.78 | 0 | | -------------------------------------------------------------- -| Column Total | 18 | 14 | 32 | -| | 0.563 | 0.437 | | --------------------------------------------------------------" - - expect_output(print_cross(k), pim) + expect_snapshot(ds_cross_table(mt, cyl, vs)) }) test_that("output from print_screener matches expected output", { mt <- mtcars mt[, c(2, 8:11)] <- lapply(mt[, c(2, 8:11)], factor) - mt[sample(1:nrow(mt), 12), sample(1:ncol(mt), 6)] <- NA - k <- ds_screener(mt) - pim <- "----------------------------------------------------------------------- -| Column Name | Data Type | Levels | Missing | Missing (%) | - ----------------------------------------------------------------------- - | mpg | numeric | NA | 0 | 0 | - | cyl | factor | 4 6 8 | 12 | 37.5 | - | disp | numeric | NA | 0 | 0 | - | hp | numeric | NA | 12 | 37.5 | - | drat | numeric | NA | 0 | 0 | - | wt | numeric | NA | 0 | 0 | - | qsec | numeric | NA | 12 | 37.5 | - | vs | factor | 0 1 | 12 | 37.5 | - | am | factor | 0 1 | 12 | 37.5 | - | gear | factor | 3 4 5 | 12 | 37.5 | - | carb | factor |1 2 3 4 6 8| 0 | 0 | - ----------------------------------------------------------------------- - - Overall Missing Values 72 - Percentage of Missing Values 20.45 % - Rows with Missing Values 12 - Columns With Missing Values 6 " - - expect_output(print_screen(k), pim) + expect_snapshot(ds_screener(mt)) }) test_that("output from print_fcont matches the expected result", { - k <- ds_freq_table(mtcars, mpg) - pim <- " Variable: mpg -|-----------------------------------------------------------------------| -| Bins | Frequency | Cum Frequency | Percent | Cum Percent | -|-----------------------------------------------------------------------| -| 10.4 - 15.1 | 6 | 6 | 18.75 | 18.75 | -|-----------------------------------------------------------------------| -| 15.1 - 19.8 | 12 | 18 | 37.5 | 56.25 | -|-----------------------------------------------------------------------| -| 19.8 - 24.5 | 8 | 26 | 25 | 81.25 | -|-----------------------------------------------------------------------| -| 24.5 - 29.2 | 2 | 28 | 6.25 | 87.5 | -|-----------------------------------------------------------------------| -| 29.2 - 33.9 | 4 | 32 | 12.5 | 100 | -|-----------------------------------------------------------------------|" - - expect_output(print_fcont(k), pim) + expect_snapshot(ds_freq_table(mtcars, mpg)) }) test_that("output from print_fcont is as expected when data has missing values", { mt <- mtcarz mt$mpg[c(3, 10, 14, 19)] <- NA - k <- ds_freq_table(mtcars, mpg) - pim <- " Variable: mpg -|-----------------------------------------------------------------------| -| Bins | Frequency | Cum Frequency | Percent | Cum Percent | -|-----------------------------------------------------------------------| -| 10.4 - 15.1 | 6 | 6 | 21.43 | 21.43 | -|-----------------------------------------------------------------------| -| 15.1 - 19.8 | 10 | 16 | 35.71 | 57.14 | -|-----------------------------------------------------------------------| -| 19.8 - 24.5 | 7 | 23 | 25 | 82.14 | -|-----------------------------------------------------------------------| -| 24.5 - 29.2 | 2 | 25 | 7.14 | 89.29 | -|-----------------------------------------------------------------------| -| 29.2 - 33.9 | 3 | 28 | 10.71 | 100 | -|-----------------------------------------------------------------------| -| Missing | 4 | - | 12.50 | - | -|-----------------------------------------------------------------------| -| Total | 32 | - | 100.00 | - | -|-----------------------------------------------------------------------|" - - expect_output(print_fcont(k), pim) + expect_snapshot(ds_freq_table(mtcars, mpg)) }) test_that("output from freq_table matches the expected result", { - k <- ds_freq_table(mt, cyl) - pim <- " Variable: cyl) -|--------------------------------------------------------------------------| - | Cumulative Cumulative | - | Levels | Frequency | Frequency | Percent | Percent | - |--------------------------------------------------------------------------| - | 4 | 7 | 7 | 35 | 35 | - |--------------------------------------------------------------------------| - | 6 | 4 | 11 | 20 | 55 | - |--------------------------------------------------------------------------| - | 8 | 9 | 20 | 45 | 100 | - |--------------------------------------------------------------------------| - " - expect_output(print_ftable(k), pim) + expect_snapshot(ds_freq_table(mt, cyl)) }) test_that("output from freq_table is as expected when data has missing values", { mt <- mtcarz mt$cyl[c(3, 10, 14, 19)] <- NA - k <- ds_freq_table(mt, cyl) - pim <- " Variable: cyl ------------------------------------------------------------------------ -Levels Frequency Cum Frequency Percent Cum Percent ------------------------------------------------------------------------ - 4 9 9 32.14 32.14 ------------------------------------------------------------------------ - 6 6 15 21.43 53.57 ------------------------------------------------------------------------ - 8 13 28 46.43 100 ------------------------------------------------------------------------ -Missing 4 - - ------------------------------------------------------------------------ - Total 32 - 100.00 - ------------------------------------------------------------------------" - expect_output(print_ftable(k), pim) + expect_snapshot(ds_freq_table(mt, cyl)) }) test_that("output from group_summary matches the expected result", { - k <- ds_group_summary(mt, cyl, mpg) - pim <- " mpg by cyl ------------------------------------------------------------------------------------------ -| Statistic/Levels| 4| 6| 8| ------------------------------------------------------------------------------------------ -| Obs| 11| 7| 14| -| Maximum| 21.4| 17.8| 10.4| -| Minimum| 33.9| 21.4| 19.2| -| Mean| 26.66| 19.74| 15.1| -| Median| 26| 19.7| 15.2| -| Mode| 22.8| 21| 10.4| -| Std. Deviation| 4.51| 1.45| 2.56| -| Variance| 20.34| 2.11| 6.55| -| Skewness| 0.35| -0.26| -0.46| -| Kurtosis| -1.43| -1.83| 0.33| -| Uncorrected SS| 8023.83| 2741.14| 3277.34| -| Corrected SS| 203.39| 12.68| 85.2| -| Coeff Variation| 16.91| 7.36| 16.95| -| Std. Error Mean| 1.36| 0.55| 0.68| -| Range| 12.5| 3.6| 8.8| -| Interquartile Range| 7.6| 2.35| 1.85| ------------------------------------------------------------------------------------------" - - expect_output(print_group(k), pim) + expect_snapshot(ds_group_summary(mt, cyl, mpg)) }) test_that("output from print_ftable2 matches the expected result", { mt <- mtcars mt[, c(2, 8:11)] <- lapply(mt[, c(2, 8:11)], factor) - pim <- " Variable: cyl -|--------------------------------------------------------------------------| -| Cumulative Cumulative | -| Levels | Frequency | Frequency | Percent | Percent | -|--------------------------------------------------------------------------| -| 4 | 11 | 11 | 34.38 | 34.38 | -|--------------------------------------------------------------------------| -| 6 | 7 | 18 | 21.88 | 56.25 | -|--------------------------------------------------------------------------| -| 8 | 14 | 32 | 43.75 | 100 | -|--------------------------------------------------------------------------| - - - Variable: vs -|--------------------------------------------------------------------------| -| Cumulative Cumulative | -| Levels | Frequency | Frequency | Percent | Percent | -|--------------------------------------------------------------------------| -| 0 | 18 | 18 | 56.25 | 56.25 | -|--------------------------------------------------------------------------| -| 1 | 14 | 32 | 43.75 | 100 | -|--------------------------------------------------------------------------| - - - Variable: am -|--------------------------------------------------------------------------| -| Cumulative Cumulative | -| Levels | Frequency | Frequency | Percent | Percent | -|--------------------------------------------------------------------------| -| 0 | 19 | 19 | 59.38 | 59.38 | -|--------------------------------------------------------------------------| -| 1 | 13 | 32 | 40.62 | 100 | -|--------------------------------------------------------------------------| - - - Variable: gear -|--------------------------------------------------------------------------| -| Cumulative Cumulative | -| Levels | Frequency | Frequency | Percent | Percent | -|--------------------------------------------------------------------------| -| 3 | 15 | 15 | 46.88 | 46.88 | -|--------------------------------------------------------------------------| -| 4 | 12 | 27 | 37.5 | 84.38 | -|--------------------------------------------------------------------------| -| 5 | 5 | 32 | 15.62 | 100 | -|--------------------------------------------------------------------------| - - - Variable: carb -|--------------------------------------------------------------------------| -| Cumulative Cumulative | -| Levels | Frequency | Frequency | Percent | Percent | -|--------------------------------------------------------------------------| -| 1 | 7 | 7 | 21.88 | 21.88 | -|--------------------------------------------------------------------------| -| 2 | 10 | 17 | 31.25 | 53.12 | -|--------------------------------------------------------------------------| -| 3 | 3 | 20 | 9.38 | 62.5 | -|--------------------------------------------------------------------------| -| 4 | 10 | 30 | 31.25 | 93.75 | -|--------------------------------------------------------------------------| -| 6 | 1 | 31 | 3.12 | 96.88 | -|--------------------------------------------------------------------------| -| 8 | 1 | 32 | 3.12 | 100 | -|--------------------------------------------------------------------------| -" - expect_output(ds_auto_freq_table(mt), pim) + expect_snapshot(ds_auto_freq_table(mt)) }) test_that("output from ds_auto_freq_table() is as expected when data has missing values", { - pim <- " Variable: cyl ------------------------------------------------------------------------ -Levels Frequency Cum Frequency Percent Cum Percent ------------------------------------------------------------------------ - 4 9 9 32.14 32.14 ------------------------------------------------------------------------ - 6 6 15 21.43 53.57 ------------------------------------------------------------------------ - 8 13 28 46.43 100 ------------------------------------------------------------------------ -Missing 4 - 12.50 - ------------------------------------------------------------------------ - Total 32 - 100.00 - ------------------------------------------------------------------------ - - Variable: gear ------------------------------------------------------------------------ -Levels Frequency Cum Frequency Percent Cum Percent ------------------------------------------------------------------------ - 3 13 13 46.43 46.43 ------------------------------------------------------------------------ - 4 10 23 35.71 82.14 ------------------------------------------------------------------------ - 5 5 28 17.86 100 ------------------------------------------------------------------------ -Missing 4 - 12.50 - ------------------------------------------------------------------------ - Total 32 - 100.00 - ------------------------------------------------------------------------" - fdata <- dplyr::select(mtcarz, cyl, gear) fdata$cyl[c(3, 10, 14, 19)] <- NA fdata$gear[c(3, 8, 17, 24)] <- NA - expect_output(ds_auto_freq_table(fdata), pim) + expect_snapshot(ds_auto_freq_table(fdata)) }) test_that("output from print_cross2 matches the expected result", { mt <- mtcars mt[, c(2, 8, 9)] <- lapply(mt[, c(2, 8, 9)], factor) - pim <- " Cell Contents - |---------------| - | Frequency | - | Percent | - | Row Pct | - | Col Pct | - |---------------| - - Total Observations: 32 - - cyl vs vs -------------------------------------------------------------- -| | vs | -------------------------------------------------------------- -| cyl | 1 | 2 | Row Total | -------------------------------------------------------------- -| 1 | 1 | 10 | 11 | -| | 0.031 | 0.312 | | -| | 0.09 | 0.91 | 0.34 | -| | 0.06 | 0.71 | | -------------------------------------------------------------- -| 2 | 3 | 4 | 7 | -| | 0.094 | 0.125 | | -| | 0.43 | 0.57 | 0.22 | -| | 0.17 | 0.29 | | -------------------------------------------------------------- -| 3 | 14 | 0 | 14 | -| | 0.438 | 0 | | -| | 1 | 0 | 0.44 | -| | 0.78 | 0 | | -------------------------------------------------------------- -| Column Total | 18 | 14 | 32 | -| | 0.563 | 0.437 | | -------------------------------------------------------------- - - - cyl vs am -------------------------------------------------------------- -| | am | -------------------------------------------------------------- -| cyl | 1 | 2 | Row Total | -------------------------------------------------------------- -| 1 | 3 | 8 | 11 | -| | 0.094 | 0.25 | | -| | 0.27 | 0.73 | 0.34 | -| | 0.16 | 0.62 | | -------------------------------------------------------------- -| 2 | 4 | 3 | 7 | -| | 0.125 | 0.094 | | -| | 0.57 | 0.43 | 0.22 | -| | 0.21 | 0.23 | | -------------------------------------------------------------- -| 3 | 12 | 2 | 14 | -| | 0.375 | 0.062 | | -| | 0.86 | 0.14 | 0.44 | -| | 0.63 | 0.15 | | -------------------------------------------------------------- -| Column Total | 19 | 13 | 32 | -| | 0.594 | 0.406 | | -------------------------------------------------------------- - - - vs vs am -------------------------------------------------------------- -| | am | -------------------------------------------------------------- -| vs | 1 | 2 | Row Total | -------------------------------------------------------------- -| 1 | 12 | 6 | 18 | -| | 0.375 | 0.188 | | -| | 0.67 | 0.33 | 0.56 | -| | 0.63 | 0.46 | | -------------------------------------------------------------- -| 2 | 7 | 7 | 14 | -| | 0.219 | 0.219 | | -| | 0.5 | 0.5 | 0.44 | -| | 0.37 | 0.54 | | -------------------------------------------------------------- -| Column Total | 19 | 13 | 32 | -| | 0.594 | 0.407 | | -------------------------------------------------------------- - -" - expect_output(ds_auto_cross_table(mt), pim) + expect_snapshot(ds_auto_cross_table(mt)) }) diff --git a/tests/testthat/test-plots.R b/tests/testthat/test-plots.R index b1c1862..db8a9af 100644 --- a/tests/testthat/test-plots.R +++ b/tests/testthat/test-plots.R @@ -1,5 +1,3 @@ -context("test-plots") - ndata <- dplyr::select(mtcarz, mpg, disp) fdata <- dplyr::select(mtcarz, cyl, gear) mdata <- dplyr::select(mtcarz, cyl, mpg) @@ -7,95 +5,95 @@ mdata <- dplyr::select(mtcarz, cyl, mpg) test_that("output from ds_screener is as expected", { x <- ds_screener(airquality) p <- plot(x) - expect_doppelganger("ds_screener_1", p) + vdiffr::expect_doppelganger("ds_screener_1", p) }) test_that("output from ds_plot_scatter is as expected", { p <- ds_plot_scatter(mtcarz, mpg, disp, print_plot = FALSE) - expect_doppelganger("ds_plot_scatter_1", p[[1]]) - expect_doppelganger("ds_plot_scatter_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_scatter_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_scatter_2", p[[2]]) q <- ds_plot_scatter(ndata, print_plot = FALSE) - expect_doppelganger("ds_plot_scatter_3", q[[1]]) - expect_doppelganger("ds_plot_scatter_4", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_scatter_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_scatter_4", q[[2]]) }) test_that("output from ds_plot_histogram is as expected", { p <- ds_plot_histogram(mtcarz, mpg, disp, hp, print_plot = FALSE) - expect_doppelganger("ds_plot_hist_1", p[[1]]) - expect_doppelganger("ds_plot_hist_2", p[[2]]) - expect_doppelganger("ds_plot_hist_3", p[[3]]) + vdiffr::expect_doppelganger("ds_plot_hist_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_hist_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_hist_3", p[[3]]) q <- ds_plot_histogram(ndata, print_plot = FALSE) - expect_doppelganger("ds_plot_hist_4", q[[1]]) - expect_doppelganger("ds_plot_hist_5", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_hist_4", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_hist_5", q[[2]]) }) test_that("output from ds_plot_density is as expected", { # skip_if(getRversion() > '4.0.3') p <- ds_plot_density(mtcarz, mpg, disp, hp, print_plot = FALSE) - expect_doppelganger("ds_plot_density_1", p[[1]]) - expect_doppelganger("ds_plot_density_2", p[[2]]) - expect_doppelganger("ds_plot_density_3", p[[3]]) + vdiffr::expect_doppelganger("ds_plot_density_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_density_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_density_3", p[[3]]) q <- ds_plot_density(ndata, print_plot = FALSE) - expect_doppelganger("ds_plot_density_4", q[[1]]) - expect_doppelganger("ds_plot_density_5", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_density_4", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_density_5", q[[2]]) }) test_that("output from ds_plot_bar is as expected", { p <- ds_plot_bar(mtcarz, cyl, gear, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_1", p[[1]]) - expect_doppelganger("ds_plot_bar_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_2", p[[2]]) q <- ds_plot_bar(fdata, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_3", q[[1]]) - expect_doppelganger("ds_plot_bar_4", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_4", q[[2]]) }) test_that("output from ds_plot_box_single is as expected", { p <- ds_plot_box_single(mtcarz, mpg, disp, hp, print_plot = FALSE) - expect_doppelganger("ds_plot_box_single_1", p[[1]]) - expect_doppelganger("ds_plot_box_single_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_box_single_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_box_single_2", p[[2]]) q <- ds_plot_box_single(ndata, print_plot = FALSE) - expect_doppelganger("ds_plot_box_single_3", q[[1]]) - expect_doppelganger("ds_plot_box_single_4", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_box_single_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_box_single_4", q[[2]]) }) test_that("output from ds_plot_bar_stacked is as expected", { p <- ds_plot_bar_stacked(mtcarz, cyl, gear, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_stacked_1", p[[1]]) - expect_doppelganger("ds_plot_bar_stacked_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_stacked_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_stacked_2", p[[2]]) q <- ds_plot_bar_stacked(fdata, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_stacked_3", q[[1]]) - expect_doppelganger("ds_plot_bar_stacked_4", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_stacked_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_stacked_4", q[[2]]) }) test_that("output from ds_plot_bar_grouped is as expected", { p <- ds_plot_bar_grouped(mtcarz, cyl, gear, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_grouped_1", p[[1]]) - expect_doppelganger("ds_plot_bar_grouped_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_grouped_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_grouped_2", p[[2]]) q <- ds_plot_bar_grouped(fdata, print_plot = FALSE) - expect_doppelganger("ds_plot_bar_grouped_3", q[[1]]) - expect_doppelganger("ds_plot_bar_grouped_4", q[[2]]) + vdiffr::expect_doppelganger("ds_plot_bar_grouped_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_bar_grouped_4", q[[2]]) }) test_that("output from ds_plot_box_group is as expected", { p <- ds_plot_box_group(mtcarz, cyl, gear, mpg, print_plot = FALSE) - expect_doppelganger("ds_plot_box_group_1", p[[1]]) - expect_doppelganger("ds_plot_box_group_2", p[[2]]) + vdiffr::expect_doppelganger("ds_plot_box_group_1", p[[1]]) + vdiffr::expect_doppelganger("ds_plot_box_group_2", p[[2]]) q <- ds_plot_box_group(mdata, print_plot = FALSE) - expect_doppelganger("ds_plot_box_group_3", q[[1]]) + vdiffr::expect_doppelganger("ds_plot_box_group_3", q[[1]]) }) diff --git a/tests/testthat/test-screen.R b/tests/testthat/test-screen.R index 472e099..f442caa 100644 --- a/tests/testthat/test-screen.R +++ b/tests/testthat/test-screen.R @@ -1,5 +1,3 @@ -context("ds_screener") - test_that("output from ds_screener matches the expected result", { mt <- mtcars mt[, c(2, 8:11)] <- lapply(mt[, c(2, 8:11)], factor) @@ -8,31 +6,31 @@ test_that("output from ds_screener matches the expected result", { expect_equal(k$Rows, nrow(mt)) expect_equal(k$Columns, ncol(mt)) - expect_equivalent(k$Variables, names(mt)) - expect_equivalent(k$Types, c( + expect_equal(k$Variables, names(mt)) + expect_equal(k$Types, c( "numeric", "factor", "numeric", "numeric", "numeric", "numeric", "numeric", "factor", "factor", "factor", "factor" - )) + ), ignore_attr = TRUE) expect_equal(unname(k$Count), rep(32, 11)) - expect_equivalent(k$nlevels, list( + expect_equal(k$nlevels, list( mpg = 0, cyl = 3, disp = 0, hp = 0, drat = 0, wt = 0, qsec = 0, vs = 2, am = 2, gear = 3, carb = 6 )) - expect_equivalent(k$levels, list( + expect_equal(k$levels, list( mpg = NA, cyl = c("4", "6", "8"), disp = NA, hp = NA, drat = NA, wt = NA, qsec = NA, vs = c("0", "1"), am = c("0", "1"), gear = c("3", "4", "5"), carb = c("1", "2", "3", "4", "6", "8") )) - expect_equivalent(k$Missing, c( + expect_equal(k$Missing, c( mpg = 0, cyl = 12, disp = 0, hp = 12, drat = 0, wt = 0, qsec = 12, vs = 12, am = 12, gear = 12, carb = 0 )) - expect_equivalent(k$MissingPer, c( + expect_equal(k$MissingPer, c( mpg = 0, cyl = 37.5, disp = 0, hp = 37.5, drat = 0, wt = 0, qsec = 37.5, vs = 37.5, am = 37.5, gear = 37.5, carb = 0 diff --git a/tests/testthat/test-summary-stats.R b/tests/testthat/test-summary-stats.R index bdf7b93..42757ee 100644 --- a/tests/testthat/test-summary-stats.R +++ b/tests/testthat/test-summary-stats.R @@ -1,12 +1,18 @@ -context("test-summary-stats") - ndata <- dplyr::select(mtcarz, mpg) -test_that("output from ds_summary is as expected", { +test_that("output from ds_summary is as expected when data is a data.frame", { actual <- round(ds_summary(mtcarz, mpg)$variance, 2) - expected <- 36.32 - expect_equal(actual, expected) + expected <- 36.32 + expect_equal(actual, expected) + +}) + +test_that("output from ds_summary is as expected when data is numeric", { + + actual <- round(ds_summary(mtcarz$mpg)$variance, 2) + expected <- 36.32 + expect_equal(actual, expected) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 5cdff89..cf11ca5 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,5 +1,3 @@ -context("utils") - test_that("output from formatc matches the expected result", { expect_equal(formatc(3, 11), " 3 ") expect_equal(formatc("hello", 7), " hello ") @@ -69,14 +67,14 @@ test_that("output from formatter_freq matches the expected result", { test_that("output from row_pct matches the expected result", { m <- matrix(c(12, 23, 37, 21), nrow = 2) exptd <- matrix(c(0.245, 0.523, 0.755, 0.477), nrow = 2) - expect_equivalent(round(row_pct(m, c(49, 44)), 3), exptd) + expect_equal(round(row_pct(m, c(49, 44)), 3), exptd, ignore_attr = TRUE) }) test_that("output from col_pct matches the expected result", { m <- matrix(c(12, 23, 37, 21), nrow = 2) exptd <- matrix(c(0.343, 0.657, 0.638, 0.362), nrow = 2) - expect_equivalent(round(col_pct(m, c(35, 58)), 3), exptd) + expect_equal(round(col_pct(m, c(35, 58)), 3), exptd, ignore_attr = TRUE) }) @@ -91,41 +89,41 @@ test_that("output from fround matches the expected result", { test_that("output form xmm matches the expected result", { - expect_equivalent(xmm(3, 2), c(-7, 13)) + expect_equal(xmm(3, 2), c(-7, 13)) }) test_that("output from seql matches the expected result", { - expect_equivalent(seql(3, 2), c(-7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13)) + expect_equal(seql(3, 2), c(-7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13)) }) test_that("output form xmmp matches the expected result", { - expect_equivalent(xmmp(3, 2, 3.5), c(-5, 11)) - expect_equivalent(xmmp(3, 2, 4.5), c(-6, 12)) + expect_equal(xmmp(3, 2, 3.5), c(-5, 11)) + expect_equal(xmmp(3, 2, 4.5), c(-6, 12)) }) test_that("output from seqlp matches the expected result", { - expect_equivalent(seqlp(3, 2, 2.5), c(-5, -3, -1, 1, 3, 5, 7, 9, 11)) - expect_equivalent(seqlp(3, 2, 4.5), c(-6, -4, -2, 0, 2, 4, 6, 8, 10, 12)) + expect_equal(seqlp(3, 2, 2.5), c(-5, -3, -1, 1, 3, 5, 7, 9, 11)) + expect_equal(seqlp(3, 2, 4.5), c(-6, -4, -2, 0, 2, 4, 6, 8, 10, 12)) }) test_that("output form xmn matches the expected result", { - expect_equivalent(xmn(3, 2), c(-3, 9)) + expect_equal(xmn(3, 2), c(-3, 9)) }) test_that("output from seqln matches the expected result", { - expect_equivalent(seqln(3, 2), c(-3, -1, 1, 3, 5, 7, 9)) + expect_equal(seqln(3, 2), c(-3, -1, 1, 3, 5, 7, 9)) }) test_that("output from intervals matches expected result", { - expect_equivalent(intervals(0:10, 4), c(0.0, 2.5, 5.0, 7.5, 10.0)) + expect_equal(intervals(0:10, 4), c(0.0, 2.5, 5.0, 7.5, 10.0)) }) test_that("output from freq matches the expected result", { - expect_equivalent( + expect_equal( freq(mtcars$mpg, 4, intervals(mtcars$mpg, 4)), c(10, 13, 5, 4) ) @@ -152,4 +150,4 @@ test_that("output from trimmed_mean is as expected", { expect_equal(unname(round(quant1(mt$mpg, TRUE), 2)), 15.43) expect_equal(unname(round(quant3(mt$mpg, TRUE), 2)), 21.82) -}) \ No newline at end of file +})