├── .Rbuildignore ├── .github ├── .gitignore ├── CONTRIBUTING.md ├── issue_template.md ├── pull_request_template.md └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ └── rhub.yaml ├── .gitignore ├── CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── add-cols.R ├── add-n-prop-miss.R ├── any-na-complete.R ├── cast-shadows.R ├── data-common-na-numbers.R ├── data-common-na-strings.R ├── data-oceanbuoys.R ├── data-pedestrian.R ├── data-riskfactors.R ├── geom-miss-point.R ├── geom2plotly.R ├── gg-miss-case-cumsum.R ├── gg-miss-case.R ├── gg-miss-fct.R ├── gg-miss-span.R ├── gg-miss-upset.R ├── gg-miss-var-cumsum.R ├── gg-miss-var.R ├── gg-miss-which.R ├── impute-factor.R ├── impute-fixed.R ├── impute-median.R ├── impute-mode.R ├── impute-zero.R ├── impute_below.R ├── impute_mean.R ├── label-miss.R ├── legend-draw.R ├── mcar-test.R ├── miss-complete-x-pct-prop.R ├── miss-prop-pct-summary.R ├── miss-scan-count.R ├── miss-x-cumsum.R ├── miss-x-run.R ├── miss-x-span.R ├── miss-x-summary.R ├── miss-x-table.R ├── n-prop-miss-complete-rows.R ├── n-prop-miss-complete.R ├── n-var-miss.R ├── nabular.R ├── naniar-ggproto.R ├── naniar-package.R ├── prop-pct-var-case-miss-complete.R ├── replace-to-na.R ├── replace-with-na.R ├── replace_na_with.R ├── scoped-replace-with-na.R ├── set-n-prop-miss.R ├── shade.R ├── shadow-recode.R ├── shadow-shifters.R ├── shadows.R ├── stat-miss-point.R ├── utils.R └── where-na.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── codecov.yml ├── cran-comments.md ├── data-raw ├── create-data-common-na-numbers.R ├── create-data-common-na-strings.R ├── create-data-oceanbuoys.R ├── create-data-pedestrian.R └── create-data-riskfactors.R ├── data ├── common_na_numbers.rda ├── common_na_strings.rda ├── oceanbuoys.rda ├── pedestrian.rda └── riskfactors.rda ├── inst ├── CITATION └── WORDLIST ├── man ├── add_any_miss.Rd ├── add_label_missings.Rd ├── add_label_shadow.Rd ├── add_miss_cluster.Rd ├── add_n_miss.Rd ├── add_prop_miss.Rd ├── add_shadow.Rd ├── add_shadow_shift.Rd ├── add_span_counter.Rd ├── any-all-na-complete.Rd ├── any_row_miss.Rd ├── as_shadow.Rd ├── as_shadow_upset.Rd ├── bind_shadow.Rd ├── cast_shadow.Rd ├── cast_shadow_shift.Rd ├── cast_shadow_shift_label.Rd ├── common_na_numbers.Rd ├── common_na_strings.Rd ├── draw_key.Rd ├── figures │ ├── README-facet-by-month-1.png │ ├── README-geom-miss-point-1.png │ ├── README-geom-missing-point-1.png │ ├── README-gg-miss-span-1.png │ ├── README-gg-miss-upset-1.png │ ├── README-gg-miss-var-1.png │ ├── README-gg-missing-var-1.png │ ├── README-regular-geom-point-1.png │ ├── README-shadow-impute-1.png │ ├── README-shadow-w-ggplot-1.png │ ├── README-unnamed-chunk-3-1.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-upset-plot-1.png │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-stable.svg │ ├── lifecycle-superseded.svg │ ├── logo.png │ ├── naniar-logo.png │ └── naniar-sticker.svg ├── gather_shadow.Rd ├── geom_miss_point.Rd ├── gg_miss_case.Rd ├── gg_miss_case_cumsum.Rd ├── gg_miss_fct.Rd ├── gg_miss_span.Rd ├── gg_miss_upset.Rd ├── gg_miss_var.Rd ├── gg_miss_var_cumsum.Rd ├── gg_miss_which.Rd ├── impute_below.Rd ├── impute_below.numeric.Rd ├── impute_below_all.Rd ├── impute_below_at.Rd ├── impute_below_if.Rd ├── impute_factor.Rd ├── impute_fixed.Rd ├── impute_mean.Rd ├── impute_median.Rd ├── impute_mode.Rd ├── impute_zero.Rd ├── is_shade.Rd ├── label_miss_1d.Rd ├── label_miss_2d.Rd ├── label_missings.Rd ├── mcar_test.Rd ├── miss-pct-prop-defunct.Rd ├── miss_case_cumsum.Rd ├── miss_case_summary.Rd ├── miss_case_table.Rd ├── miss_prop_summary.Rd ├── miss_scan_count.Rd ├── miss_summary.Rd ├── miss_var_cumsum.Rd ├── miss_var_run.Rd ├── miss_var_span.Rd ├── miss_var_summary.Rd ├── miss_var_table.Rd ├── miss_var_which.Rd ├── n-var-case-complete.Rd ├── n-var-case-miss.Rd ├── n_complete.Rd ├── n_complete_row.Rd ├── n_miss.Rd ├── n_miss_row.Rd ├── nabular.Rd ├── naniar-ggproto.Rd ├── naniar.Rd ├── oceanbuoys.Rd ├── pct-miss-complete-case.Rd ├── pct-miss-complete-var.Rd ├── pct_complete.Rd ├── pct_miss.Rd ├── pedestrian.Rd ├── plotly_helpers.Rd ├── prop-miss-complete-case.Rd ├── prop-miss-complete-var.Rd ├── prop_complete.Rd ├── prop_complete_row.Rd ├── prop_miss.Rd ├── prop_miss_row.Rd ├── recode_shadow.Rd ├── reexports.Rd ├── replace_na_with.Rd ├── replace_to_na.Rd ├── replace_with_na.Rd ├── replace_with_na_all.Rd ├── replace_with_na_at.Rd ├── replace_with_na_if.Rd ├── riskfactors.Rd ├── scoped-impute_mean.Rd ├── scoped-impute_median.Rd ├── set-prop-n-miss.Rd ├── shade.Rd ├── shadow_long.Rd ├── shadow_shift.Rd ├── stat_miss_point.Rd ├── unbinders.Rd ├── where.Rd ├── where_na.Rd ├── which_are_shade.Rd └── which_na.Rd ├── missingness-data-structures.png ├── naniar.Rproj ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── revdep ├── .gitignore ├── README.md ├── cran.md ├── failures.md └── problems.md ├── tests ├── figs │ ├── deps.txt │ ├── geom-miss-point │ │ ├── geom-miss-point-jitter.svg │ │ ├── geom-miss-point-prop-jitter.svg │ │ ├── geom-miss-point-prop.svg │ │ └── geom-miss-point.svg │ ├── gg-miss-case-cumsum │ │ └── gg-miss-case-cumsum.svg │ ├── gg-miss-case │ │ ├── gg-miss-case-group-and-sort-show-pct.svg │ │ ├── gg-miss-case-group-and-sort.svg │ │ ├── gg-miss-case-group-show-pct.svg │ │ ├── gg-miss-case-group.svg │ │ ├── gg-miss-case-plot-show-pct.svg │ │ ├── gg-miss-case-sort-show-pct.svg │ │ ├── gg-miss-case-sort.svg │ │ └── gg-miss-case.svg │ ├── gg-miss-fct │ │ └── gg-miss-fct.svg │ ├── gg-miss-span │ │ ├── gg-miss-span-group.svg │ │ └── gg-miss-span.svg │ ├── gg-miss-var-cumsum │ │ └── gg-miss-var-cumsum.svg │ ├── gg-miss-var-plot │ │ ├── gg-miss-var-group-pct.svg │ │ ├── gg-miss-var-pct.svg │ │ ├── gg-miss-var-plot-group.svg │ │ └── gg-miss-var.svg │ ├── gg-miss-which │ │ └── gg-miss-which.svg │ └── test-gg-miss-upset │ │ └── gg-miss-upset.svg ├── spelling.R ├── testthat.R └── testthat │ ├── _snaps │ ├── add-label-shadow.md │ ├── add-shadow.md │ ├── as-shadow.md │ ├── as_shadow_upset.md │ ├── cast-shadow-shift-label.md │ ├── cast-shadow-shift.md │ ├── defunct.md │ ├── gather-shadow.md │ ├── geom-miss-point │ │ ├── geom-miss-point-jitter.svg │ │ ├── geom-miss-point-plot-date-prop-jitter.svg │ │ ├── geom-miss-point-plot-date.svg │ │ ├── geom-miss-point-prop-jitter.svg │ │ ├── geom-miss-point-prop.svg │ │ └── geom-miss-point.svg │ ├── gg-miss-case-cumsum │ │ └── gg-miss-case-cumsum.svg │ ├── gg-miss-case │ │ ├── gg-miss-case-group-and-sort-show-pct.svg │ │ ├── gg-miss-case-group-and-sort.svg │ │ ├── gg-miss-case-group-show-pct.svg │ │ ├── gg-miss-case-group.svg │ │ ├── gg-miss-case-plot-show-pct.svg │ │ ├── gg-miss-case-sort-show-pct.svg │ │ ├── gg-miss-case-sort.svg │ │ └── gg-miss-case.svg │ ├── gg-miss-fct │ │ └── gg-miss-fct.svg │ ├── gg-miss-span │ │ ├── gg-miss-span-group.svg │ │ └── gg-miss-span.svg │ ├── gg-miss-var-cumsum │ │ └── gg-miss-var-cumsum.svg │ ├── gg-miss-var-plot │ │ ├── gg-miss-var-group-pct.svg │ │ ├── gg-miss-var-pct.svg │ │ ├── gg-miss-var-plot-group.svg │ │ └── gg-miss-var.svg │ ├── gg-miss-which │ │ └── gg-miss-which.svg │ ├── impute-below.md │ ├── impute-median.md │ ├── impute_mean.md │ ├── label-miss-1d.md │ ├── label-miss-2d.md │ ├── miss-case-summary.md │ ├── miss-case-table.md │ ├── miss-prop-summary.md │ ├── miss-scan-count.md │ ├── miss-summary.md │ ├── miss-var-case-cumsum.md │ ├── miss-var-summary.md │ ├── miss-var-table.md │ ├── miss-var-which.md │ ├── miss-x-pct.md │ ├── nabular.md │ ├── prop_row.md │ ├── replace-with-na-scoped-var.md │ ├── set-n-prop-miss.md │ ├── shade.md │ ├── shadow-long.md │ ├── shadow-shift.md │ └── special-missing-values.md │ ├── test-add-any-miss.R │ ├── test-add-label-missings.R │ ├── test-add-label-shadow.R │ ├── test-add-n-miss.R │ ├── test-add-prop-miss.R │ ├── test-add-shadow-shift.R │ ├── test-add-shadow.R │ ├── test-all-any-na.R │ ├── test-as-shadow.R │ ├── test-as_shadow_upset.R │ ├── test-cast-shadow-shift-label.R │ ├── test-cast-shadow-shift.R │ ├── test-cast-shadow.R │ ├── test-defunct.R │ ├── test-gather-shadow.R │ ├── test-geom-miss-point.R │ ├── test-gg-miss-case-cumsum.R │ ├── test-gg-miss-case.R │ ├── test-gg-miss-fct.R │ ├── test-gg-miss-span.R │ ├── test-gg-miss-var-cumsum.R │ ├── test-gg-miss-var-plot.R │ ├── test-gg-miss-which.R │ ├── test-gg_miss_upset.R │ ├── test-impute-below-at.R │ ├── test-impute-below.R │ ├── test-impute-factor.R │ ├── test-impute-fixed.R │ ├── test-impute-median.R │ ├── test-impute-mode.R │ ├── test-impute-zero.R │ ├── test-impute_mean.R │ ├── test-label-miss-1d.R │ ├── test-label-miss-2d.R │ ├── test-label-shadow.R │ ├── test-mcar-test.R │ ├── test-miss-case-summary.R │ ├── test-miss-case-table.R │ ├── test-miss-prop-summary.R │ ├── test-miss-scan-count.R │ ├── test-miss-summary.R │ ├── test-miss-var-case-cumsum.R │ ├── test-miss-var-run.R │ ├── test-miss-var-span.R │ ├── test-miss-var-summary.R │ ├── test-miss-var-table.R │ ├── test-miss-var-which.R │ ├── test-miss-x-pct.R │ ├── test-n-complete.R │ ├── test-n-miss.R │ ├── test-nabular.R │ ├── test-prop-cases-not-zero.R │ ├── test-prop-complete.R │ ├── test-prop-miss.R │ ├── test-prop_row.R │ ├── test-replace-with-na-scoped-var.R │ ├── test-replace-with-na.R │ ├── test-replace_na_with.R │ ├── test-set-n-prop-miss.R │ ├── test-shade-verifiers.R │ ├── test-shade.R │ ├── test-shadow-expand-relevel.R │ ├── test-shadow-identifiers.R │ ├── test-shadow-long.R │ ├── test-shadow-shift.R │ ├── test-special-missing-values.R │ ├── test-test-any-miss.R │ └── test-unbind.R └── vignettes ├── .gitignore ├── exploring-imputed-values.Rmd ├── missingness-data-structures.png ├── naniar-visualisation.Rmd ├── naniar.Rmd ├── replace-with-na.Rmd └── special-missing-values.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^README\.Rmd$ 5 | ^README-.*\.png$ 6 | ^appveyor\.yml$ 7 | ^CONDUCT\.md$ 8 | ^\.travis\.yml$ 9 | ^codecov\.yml$ 10 | ^docs$ 11 | ^doc$ 12 | ^pkgdown$ 13 | ^_pkgdown\.yml$ 14 | ^missingness-data-structures\.png$ 15 | ^README-figs$ 16 | ^data-raw$ 17 | ^\.github$ 18 | ^cran-comments\.md$ 19 | ^LICENSE\.md$ 20 | .Rprofile 21 | ^\.github/workflows/R-CMD-check\.yaml$ 22 | ^\.github/workflows/pkgdown\.yaml$ 23 | ^revdep$ 24 | ^CRAN-SUBMISSION$ 25 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTING # 2 | 3 | ### Please contribute! 4 | 5 | We love collaboration. 6 | 7 | ### Bugs? 8 | 9 | * Submit an issue on the [Issues page](https://github.com/{owner}/{repo}/issues) 10 | 11 | ### Code contributions 12 | 13 | * Fork this repo to your Github account 14 | * Clone your version on your account down to your machine from your account, e.g,. `git clone https://github.com//{repo}.git` 15 | * Make sure to track progress upstream (i.e., on our version of `{repo}` at `{owner}/{repo}`) by doing `git remote add upstream https://github.com/{owner}/{repo}.git`. Before making changes make sure to pull changes in from upstream by doing either `git fetch upstream` then merge later or `git pull upstream` to fetch and merge in one step 16 | * Make your changes (bonus points for making changes on a new feature branch) 17 | * Push up to your account 18 | * Submit a pull request to home base (likely master branch, but check to make sure) at `{owner}/{repo}` 19 | 20 | ### Prefer to Email? 21 | 22 | I will be able to better help you if you post an issue but otherwise, you can find my contact details in the `DESCRIPTION` file of this repo. 23 | 24 | ### Thanks for contributing! 25 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | Hi there! 2 | 3 | Thanks for filing an issue - it would be really helpful for me if you can include a minimal reproducible example (known as a `reprex`) if you have a problem you'd like to tell me about. The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it. If you've never heard of a reprex before, start by reading , and follow the advice further down the page. 4 | 5 | Please, _Do NOT_ include session info unless it's explicitly asked for, or use`reprex::reprex(..., si = TRUE)` to hide it away. 6 | 7 | Delete these instructions once you have read them. 8 | 9 | --- 10 | 11 | Brief description of the problem 12 | 13 | ```r 14 | # insert reprex here 15 | ``` 16 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | ## Related Issue 7 | 10 | 11 | ## Example 12 | 14 | 15 | ## Tests 16 | 18 | 19 | ## NEWS + DESCRIPTION 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v4 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 51 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | permissions: 23 | contents: write 24 | steps: 25 | - uses: actions/checkout@v4 26 | 27 | - uses: r-lib/actions/setup-pandoc@v2 28 | 29 | - uses: r-lib/actions/setup-r@v2 30 | with: 31 | use-public-rspm: true 32 | 33 | - uses: r-lib/actions/setup-r-dependencies@v2 34 | with: 35 | extra-packages: any::pkgdown, local::. 36 | needs: website 37 | 38 | - name: Build site 39 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 40 | shell: Rscript {0} 41 | 42 | - name: Deploy to GitHub pages 🚀 43 | if: github.event_name != 'pull_request' 44 | uses: JamesIves/github-pages-deploy-action@v4.5.0 45 | with: 46 | clean: false 47 | branch: gh-pages 48 | folder: docs 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | *.DS_Store 5 | inst/doc 6 | inst/*.html 7 | docs/ 8 | docs 9 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016-2018 2 | COPYRIGHT HOLDER: Nicholas Tierney 3 | -------------------------------------------------------------------------------- /R/data-common-na-numbers.R: -------------------------------------------------------------------------------- 1 | #' Common number values for NA 2 | #' 3 | #' This vector contains common number values of NA (missing), which is aimed to 4 | #' be used inside naniar functions [miss_scan_count()] and 5 | #' [replace_with_na()]. The current list of numbers can be found by printing 6 | #' out `common_na_numbers`. It is a useful way to explore your data for 7 | #' possible missings, but I strongly warn against using this to replace NA 8 | #' values without very carefully looking at the incidence for each of the 9 | #' cases. Common NA strings are in the data object `common_na_strings`. 10 | #' 11 | #' @note original discussion here \url{https://github.com/njtierney/naniar/issues/168} 12 | #' 13 | #' @name common_na_numbers 14 | #' @docType data 15 | #' @examples 16 | #' 17 | #' dat_ms <- tibble::tribble(~x, ~y, ~z, 18 | #' 1, "A", -100, 19 | #' 3, "N/A", -99, 20 | #' NA, NA, -98, 21 | #' -99, "E", -101, 22 | #' -98, "F", -1) 23 | #' 24 | #' miss_scan_count(dat_ms, -99) 25 | #' miss_scan_count(dat_ms, c("-99","-98","N/A")) 26 | #' common_na_numbers 27 | #' miss_scan_count(dat_ms, common_na_numbers) 28 | "common_na_numbers" 29 | -------------------------------------------------------------------------------- /R/data-common-na-strings.R: -------------------------------------------------------------------------------- 1 | #' Common string values for NA 2 | #' 3 | #' This vector contains common values of NA (missing), which is aimed to 4 | #' be used inside naniar functions [miss_scan_count()] and 5 | #' [replace_with_na()]. The current list of 6 | #' strings used can be found by printing out `common_na_strings`. It is a 7 | #' useful way to explore your data for possible missings, but I strongly warn 8 | #' against using this to replace NA values without very carefully looking at 9 | #' the incidence for each of the cases. Please note that `common_na_strings` 10 | #' uses `\\` around the "?", "." and "*" characters to protect against using 11 | #' their wildcard features in grep. Common NA numbers are in the data object 12 | #' `common_na_numbers`. 13 | #' 14 | #' @note original discussion here \url{https://github.com/njtierney/naniar/issues/168} 15 | #' @name common_na_strings 16 | #' @docType data 17 | #' @examples 18 | #' 19 | #' dat_ms <- tibble::tribble(~x, ~y, ~z, 20 | #' 1, "A", -100, 21 | #' 3, "N/A", -99, 22 | #' NA, NA, -98, 23 | #' -99, "E", -101, 24 | #' -98, "F", -1) 25 | #' 26 | #' miss_scan_count(dat_ms, -99) 27 | #' miss_scan_count(dat_ms, c("-99","-98","N/A")) 28 | #' common_na_strings 29 | #' miss_scan_count(dat_ms, common_na_strings) 30 | #' replace_with_na(dat_ms, replace = list(y = common_na_strings)) 31 | "common_na_strings" 32 | -------------------------------------------------------------------------------- /R/geom2plotly.R: -------------------------------------------------------------------------------- 1 | #' @name plotly_helpers 2 | #' @title Plotly helpers (Convert a geom to a "basic" geom.) 3 | #' @description Helper functions to make it easier to automatically create 4 | #' plotly charts. This function makes it possible to convert ggplot2 geoms 5 | #' that are not included with ggplot2 itself. Users shouldn't need to use this 6 | #' function. It exists purely to allow other package authors to write their 7 | #' own conversion method(s). 8 | #' @param data the data returned by `ggplot2::ggplot_build()`. 9 | #' @param prestats_data the data before statistics are computed. 10 | #' @param layout the panel layout. 11 | #' @param params parameters for the geom, statistic, and 'constant' aesthetics 12 | #' @param p a ggplot2 object (the conversion may depend on scales, for 13 | #' instance). 14 | #' @param ... currently ignored 15 | #' @keywords internal 16 | to_basic.GeomMissPoint <- function( 17 | data, 18 | prestats_data, 19 | layout, 20 | params, 21 | p, 22 | ... 23 | ) { 24 | prefix_class(data, "GeomPoint") 25 | } 26 | 27 | prefix_class <- function(x, y) { 28 | structure(x, class = unique(c(y, class(x)))) 29 | } 30 | -------------------------------------------------------------------------------- /R/gg-miss-case-cumsum.R: -------------------------------------------------------------------------------- 1 | #' Plot of cumulative sum of missing for cases 2 | #' 3 | #' A plot showing the cumulative sum of missing values for cases, reading the 4 | #' rows from the top to bottom. A default minimal theme is used, which can be 5 | #' customised as normal for ggplot. 6 | #' 7 | #' @param x a dataframe 8 | #' @param breaks the breaks for the x axis default is 20 9 | #' 10 | #' @return a ggplot object depicting the number of missings 11 | #' 12 | #' @seealso [geom_miss_point()] [gg_miss_case()] [gg_miss_fct()] [gg_miss_span()] [gg_miss_var()] [gg_miss_var_cumsum()] [gg_miss_which()] 13 | #' @export 14 | #' 15 | #' @examples 16 | #' 17 | #' gg_miss_case_cumsum(airquality) 18 | 19 | gg_miss_case_cumsum <- function(x, breaks = 20) { 20 | ggobject <- x %>% 21 | miss_case_summary(add_cumsum = TRUE) %>% 22 | ggplot(aes( 23 | x = stats::reorder(case, n_miss_cumsum), 24 | y = n_miss_cumsum, 25 | group = 1 26 | )) + 27 | geom_line(linewidth = 2) + 28 | labs(x = "Case", y = "Cumulative sum of missing values") + 29 | scale_x_discrete(breaks = seq(0, nrow(x), by = breaks)) + 30 | theme_bw() + 31 | theme(axis.text.x = element_text(angle = 45, hjust = 1)) 32 | 33 | return(ggobject) 34 | } 35 | -------------------------------------------------------------------------------- /R/gg-miss-upset.R: -------------------------------------------------------------------------------- 1 | #' Plot the pattern of missingness using an upset plot. 2 | #' 3 | #' Upset plots are a way of visualising common sets, `gg_miss_upset` shows the 4 | #' number of missing values for each of the sets of data. The default option 5 | #' of `gg_miss_upset` is taken from `UpSetR::upset` - which is to use up to 5 6 | #' sets and up to 40 interactions. We also set the ordering to by the 7 | #' frequency of the intersections. Setting `nsets = 5` means to look at 5 8 | #' variables and their combinations. The number of combinations or rather 9 | #' `intersections` is controlled by `nintersects`. If there are 40 10 | #' intersections, there will be 40 combinations of variables explored. The 11 | #' number of sets and intersections can be changed by passing arguments `nsets 12 | #' = 10` to look at 10 sets of variables, and `nintersects = 50` to look at 50 13 | #' intersections. 14 | #' 15 | #' @param data data.frame 16 | #' @param order.by (from UpSetR::upset) How the intersections in the matrix should be ordered by. Options include frequency (entered as "freq"), degree, or both in any order. See `?UpSetR::upset` for more options 17 | #' @param ... arguments to pass to upset plot - see `?UpSetR::upset` 18 | #' 19 | #' @return a ggplot visualisation of missing data 20 | #' 21 | #' @examples 22 | #' 23 | #' \dontrun{ 24 | #' gg_miss_upset(airquality) 25 | #' gg_miss_upset(riskfactors) 26 | #' gg_miss_upset(riskfactors, nsets = 10) 27 | #' gg_miss_upset(riskfactors, nsets = 10, nintersects = 10) 28 | #' } 29 | #' @export 30 | gg_miss_upset <- function(data, order.by = "freq", ...) { 31 | data %>% 32 | as_shadow_upset() %>% 33 | UpSetR::upset(order.by = order.by, ...) 34 | } 35 | -------------------------------------------------------------------------------- /R/gg-miss-var-cumsum.R: -------------------------------------------------------------------------------- 1 | #' Plot of cumulative sum of missing value for each variable 2 | #' 3 | #' A plot showing the cumulative sum of missing values for each variable, 4 | #' reading columns from the left to the right of the initial dataframe. A 5 | #' default minimal theme is used, which can be customised as normal for ggplot. 6 | #' 7 | #' @param x a data.frame 8 | #' 9 | #' @return a ggplot object showing the cumulative sum of missings over the variables 10 | #' 11 | #' @seealso [geom_miss_point()] [gg_miss_case()] [gg_miss_case_cumsum()] [gg_miss_fct()] [gg_miss_span()] [gg_miss_var()] [gg_miss_which()] 12 | 13 | #' @export 14 | #' 15 | #' @examples 16 | #' 17 | #' gg_miss_var_cumsum(airquality) 18 | 19 | gg_miss_var_cumsum <- function(x) { 20 | ggobject <- x %>% 21 | miss_var_summary(add_cumsum = TRUE) %>% 22 | ggplot(aes( 23 | x = stats::reorder(variable, n_miss_cumsum), 24 | y = n_miss_cumsum, 25 | group = 1 26 | )) + 27 | geom_line(linewidth = 2) + 28 | labs(x = "Var", y = "Cumsum of missing values") + 29 | theme_bw() + 30 | theme(axis.text.x = element_text(angle = 45, hjust = 1)) 31 | return(ggobject) 32 | } 33 | -------------------------------------------------------------------------------- /R/gg-miss-which.R: -------------------------------------------------------------------------------- 1 | #' Plot which variables contain a missing value 2 | #' 3 | #' This plot produces a set of rectangles indicating whether there is a missing 4 | #' element in a column or not. A default minimal theme is used, which can be 5 | #' customised as normal for ggplot. 6 | #' 7 | #' @param x a dataframe 8 | #' 9 | #' @return a ggplot object of which variables contains missing values 10 | #' 11 | #' @seealso [geom_miss_point()] [gg_miss_case()] [gg_miss_case_cumsum()] [gg_miss_fct()] [gg_miss_span()] [gg_miss_var()] [gg_miss_var_cumsum()] [gg_miss_which()] 12 | #' 13 | #' @export 14 | #' 15 | #' @examples 16 | #' 17 | #' gg_miss_which(airquality) 18 | 19 | gg_miss_which <- function(x) { 20 | col_na <- colSums(is.na(x)) == 0 21 | col_na_val <- dplyr::if_else(col_na, "complete", "missing") 22 | 23 | # tell us which columns have missing data 24 | ggobject <- tibble::tibble(variable = names(col_na), value = col_na_val) %>% 25 | dplyr::mutate(nheight = 1) %>% 26 | ggplot(data = ., aes(x = variable, y = nheight, fill = factor(value))) + 27 | geom_tile(colour = "white") + 28 | theme_minimal() + 29 | scale_fill_grey(name = "") + 30 | scale_x_discrete(limits = names(x)) + 31 | theme(legend.position = "none") + 32 | scale_y_discrete(breaks = c(""), labels = c("")) + 33 | labs(y = " ", x = " ") + 34 | coord_flip() 35 | 36 | return(ggobject) 37 | } 38 | -------------------------------------------------------------------------------- /R/impute-fixed.R: -------------------------------------------------------------------------------- 1 | #' Impute a fixed value into a vector with missing values 2 | #' 3 | #' This can be useful if you are imputing specific values, however we would 4 | #' generally recommend to impute using other model based approaches. See 5 | #' the `simputation` package, for example [simputation::impute_lm()]. 6 | #' 7 | #' @param x vector 8 | #' @param value value to impute 9 | #' 10 | #' @return vector with a fixed values replaced 11 | #' @export 12 | #' @name impute_fixed 13 | #' 14 | #' @examples 15 | #' 16 | #' vec <- rnorm(10) 17 | #' 18 | #' vec[sample(1:10, 3)] <- NA 19 | #' 20 | #' vec 21 | #' 22 | #' impute_fixed(vec, -999) 23 | #' 24 | #' library(dplyr) 25 | #' 26 | #' dat <- tibble( 27 | #' num = rnorm(10), 28 | #' int = rpois(10, 5), 29 | #' fct = factor(LETTERS[1:10]) 30 | #' ) %>% 31 | #' mutate( 32 | #' across( 33 | #' everything(), 34 | #' \(x) set_prop_miss(x, prop = 0.25) 35 | #' ) 36 | #' ) 37 | #' 38 | #' dat 39 | #' 40 | #' dat %>% 41 | #' nabular() %>% 42 | #' mutate( 43 | #' num = impute_fixed(num, -9999), 44 | #' int = impute_zero(int), 45 | #' fct = impute_factor(fct, "out") 46 | #' ) 47 | #' 48 | impute_fixed <- function(x, value) UseMethod("impute_fixed") 49 | 50 | #' @export 51 | #' @rdname impute_fixed 52 | impute_fixed.default <- function(x, value) { 53 | x[is.na(x)] <- value 54 | 55 | x 56 | } 57 | -------------------------------------------------------------------------------- /R/impute-zero.R: -------------------------------------------------------------------------------- 1 | #' Impute zero into a vector with missing values 2 | #' 3 | #' This can be useful if you are imputing specific values, however we would 4 | #' generally recommend to impute using other model based approaches. See 5 | #' the `simputation` package, for example [simputation::impute_lm()]. 6 | #' 7 | #' @param x vector 8 | #' 9 | #' @return vector with a fixed values replaced 10 | #' @export 11 | #' 12 | #' @examples 13 | #' 14 | #' vec <- rnorm(10) 15 | #' 16 | #' vec[sample(1:10, 3)] <- NA 17 | #' 18 | #' vec 19 | #' 20 | #' impute_zero(vec) 21 | #' 22 | #' library(dplyr) 23 | #' 24 | #' dat <- tibble( 25 | #' num = rnorm(10), 26 | #' int = rpois(10, 5), 27 | #' fct = factor(LETTERS[1:10]) 28 | #' ) %>% 29 | #' mutate( 30 | #' across( 31 | #' everything(), 32 | #' \(x) set_prop_miss(x, prop = 0.25) 33 | #' ) 34 | #' ) 35 | #' 36 | #' dat 37 | #' 38 | #' dat %>% 39 | #' nabular() %>% 40 | #' mutate( 41 | #' num = impute_fixed(num, -9999), 42 | #' int = impute_zero(int), 43 | #' fct = impute_factor(fct, "out") 44 | #' ) 45 | #' 46 | #' @rdname impute_zero 47 | impute_zero <- function(x) { 48 | impute_fixed(x = x, value = 0) 49 | } 50 | -------------------------------------------------------------------------------- /R/legend-draw.R: -------------------------------------------------------------------------------- 1 | #' Key drawing functions 2 | #' 3 | #' Each Geom has an associated function that draws the key when the geom needs 4 | #' to be displayed in a legend. These are the options built into naniar. 5 | #' 6 | #' @return A grid grob. 7 | #' @param data A single row data frame containing the scaled aesthetics to 8 | #' display in this key 9 | #' @param params A list of additional parameters supplied to the geom. 10 | #' @param size Width and height of key in mm. 11 | #' @keywords internal 12 | #' @name draw_key 13 | NULL 14 | 15 | #' @export 16 | #' @rdname draw_key 17 | draw_key_missing_point <- function(data, params, size) { 18 | grid::pointsGrob( 19 | 0.5, 20 | 0.5, 21 | pch = data$shape, 22 | gp = grid::gpar( 23 | col = data$colour, 24 | fill = alpha(data$fill, data$alpha), 25 | fontsize = data$size * .pt + data$stroke * .stroke / 2, 26 | lwd = data$stroke * .stroke / 2 27 | ) 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /R/miss-complete-x-pct-prop.R: -------------------------------------------------------------------------------- 1 | #' Proportion of variables containing missings or complete values 2 | #' 3 | #' Defunct. Please see [prop_miss_var()], [prop_complete_var()], [pct_miss_var()], [pct_complete_var()], [prop_miss_case()], [prop_complete_case()], [pct_miss_case()], [pct_complete_case()]. 4 | #' 5 | #' @param ... arguments 6 | #' @name miss-pct-prop-defunct 7 | #' @export 8 | miss_var_prop <- function(...) { 9 | .Defunct("prop_miss_var") 10 | } # end function 11 | 12 | #' @rdname miss-pct-prop-defunct 13 | #' @export 14 | complete_var_prop <- function(...) { 15 | .Defunct("prop_complete_var") 16 | } # end function 17 | 18 | #' @rdname miss-pct-prop-defunct 19 | #' @export 20 | miss_var_pct <- function(...) { 21 | .Defunct("pct_miss_var") 22 | } # end function 23 | 24 | #' @export 25 | #' @rdname miss-pct-prop-defunct 26 | complete_var_pct <- function(...) { 27 | .Defunct("pct_complete_var") 28 | } 29 | 30 | #' @export 31 | #' @rdname miss-pct-prop-defunct 32 | miss_case_prop <- function(...) { 33 | .Defunct("prop_miss_case") 34 | } 35 | 36 | #' @export 37 | #' @rdname miss-pct-prop-defunct 38 | complete_case_prop <- function(...) { 39 | .Defunct("prop_complete_case") 40 | } 41 | 42 | #' @export 43 | #' @rdname miss-pct-prop-defunct 44 | miss_case_pct <- function(...) { 45 | .Defunct("pct_miss_case") 46 | } 47 | 48 | #' @export 49 | #' @rdname miss-pct-prop-defunct 50 | complete_case_pct <- function(...) { 51 | .Defunct("pct_complete_case") 52 | } 53 | -------------------------------------------------------------------------------- /R/miss-prop-pct-summary.R: -------------------------------------------------------------------------------- 1 | #' Proportions of missings in data, variables, and cases. 2 | #' 3 | #' Return missing data info about the dataframe, the variables, and the cases. 4 | #' Specifically, returning how many elements in a dataframe contain a missing 5 | #' value, how many elements in a variable contain a missing value, and how many 6 | #' elements in a case contain a missing. 7 | #' 8 | #' @param data a dataframe 9 | #' 10 | #' @return a dataframe 11 | #' 12 | #' @seealso [pct_miss_case()] [prop_miss_case()] [pct_miss_var()] [prop_miss_var()] [pct_complete_case()] [prop_complete_case()] [pct_complete_var()] [prop_complete_var()] [miss_prop_summary()] [miss_case_summary()] [miss_case_table()] [miss_summary()] [miss_var_run()] [miss_var_span()] [miss_var_summary()] [miss_var_table()] 13 | #' 14 | #' @export 15 | #' 16 | #' @examples 17 | #' 18 | #' miss_prop_summary(airquality) 19 | #' \dontrun{ 20 | #' library(dplyr) 21 | #' # respects dplyr::group_by 22 | #' airquality %>% group_by(Month) %>% miss_prop_summary() 23 | #' } 24 | #' 25 | miss_prop_summary <- function(data) { 26 | test_if_null(data) 27 | 28 | test_if_dataframe(data) 29 | 30 | UseMethod("miss_prop_summary") 31 | } 32 | 33 | 34 | #' @export 35 | miss_prop_summary.default <- function(data) { 36 | tibble::tibble( 37 | df = prop_miss(data), 38 | var = prop_miss_var(data), 39 | case = prop_miss_case(data) 40 | ) 41 | } 42 | 43 | #' @export 44 | miss_prop_summary.grouped_df <- function(data) { 45 | group_by_fun(data, .fun = miss_prop_summary) 46 | } 47 | -------------------------------------------------------------------------------- /R/n-var-miss.R: -------------------------------------------------------------------------------- 1 | #' The number of variables or cases with missing values 2 | #' 3 | #' This function calculates the number of variables or cases that contain a missing value 4 | #' 5 | #' @param data data.frame 6 | #' 7 | #' @return integer, number of missings 8 | #' @seealso [n_var_complete()] 9 | #' @name n-var-case-miss 10 | #' 11 | #' @examples 12 | #' # how many variables contain missing values? 13 | #' n_var_miss(airquality) 14 | #' n_case_miss(airquality) 15 | #' 16 | #' @export 17 | n_var_miss <- function(data) { 18 | sum(colSums(is.na(data)) != 0) 19 | } 20 | 21 | #' @export 22 | #' @rdname n-var-case-miss 23 | n_case_miss <- function(data) { 24 | sum(rowSums(is.na(data)) != 0) 25 | } 26 | 27 | #' The number of variables with complete values 28 | #' 29 | #' This function calculates the number of variables that contain a complete value 30 | #' 31 | #' @param data data.frame 32 | #' 33 | #' @return integer number of complete values 34 | #' @seealso [n_var_miss()] 35 | #' @name n-var-case-complete 36 | #' @export 37 | #' 38 | #' @examples 39 | #' 40 | #' # how many variables contain complete values? 41 | #' n_var_complete(airquality) 42 | #' n_case_complete(airquality) 43 | #' 44 | n_var_complete <- function(data) { 45 | sum(colSums(is.na(data)) == 0) 46 | } 47 | 48 | #' @export 49 | #' @name n-var-case-complete 50 | n_case_complete <- function(data) { 51 | sum(rowSums(is.na(data)) == 0) 52 | } 53 | -------------------------------------------------------------------------------- /R/nabular.R: -------------------------------------------------------------------------------- 1 | #' Convert data into nabular form by binding shade to it 2 | #' 3 | #' Binding a shadow matrix to a regular dataframe converts it into nabular data, 4 | #' which makes it easier to visualise and work with missing data. 5 | #' 6 | #' @param data a dataframe 7 | #' @param only_miss logical - if FALSE (default) it will bind a dataframe with 8 | #' all of the variables duplicated with their shadow. Setting this to TRUE 9 | #' will bind variables only those variables that contain missing values. 10 | #' See the examples for more details. 11 | #' @param ... extra options to pass to [recode_shadow()] - a work in progress. 12 | #' 13 | #' @return data with the added variable shifted and the suffix `_NA` 14 | #' @export 15 | #' @seealso [bind_shadow()] 16 | #' 17 | #' @examples 18 | #' 19 | #' aq_nab <- nabular(airquality) 20 | #' aq_s <- bind_shadow(airquality) 21 | #' 22 | #' all.equal(aq_nab, aq_s) 23 | #' 24 | #' @export 25 | nabular <- function(data, only_miss = FALSE, ...) { 26 | bind_shadow(data = data, only_miss = only_miss, ...) 27 | } 28 | -------------------------------------------------------------------------------- /R/naniar-ggproto.R: -------------------------------------------------------------------------------- 1 | #' @name naniar-ggproto 2 | #' @title naniar-ggproto 3 | #' 4 | #' @description These are the stat and geom overrides using ggproto from ggplot2 5 | #' that make naniar work. 6 | #' 7 | NULL 8 | -------------------------------------------------------------------------------- /R/naniar-package.R: -------------------------------------------------------------------------------- 1 | #' @description 2 | #' naniar is a package to make it easier to summarise and handle missing values 3 | #' in R. It strives to do this in a way that is as consistent with tidyverse 4 | #' principles as possible. The work is fully discussed at Tierney & Cook (2023) 5 | #' . 6 | #' 7 | #' @name naniar 8 | "_PACKAGE" 9 | 10 | ## usethis namespace: start 11 | #' @importFrom lifecycle deprecated 12 | #' @import ggplot2 13 | #' @importFrom stats median 14 | #' @import rlang 15 | ## usethis namespace: end 16 | NULL 17 | 18 | 19 | if (getRversion() >= "2.15.1") utils::globalVariables(c(".")) 20 | globalVariables( 21 | c( 22 | "median", 23 | "variable_NA", 24 | ".temp", 25 | ".temp_label", 26 | "rows", 27 | "..missing..", 28 | "n_miss", 29 | "case", 30 | "variable", 31 | "value", 32 | "span_counter", 33 | "n", 34 | "n_miss", 35 | "n_in_span", 36 | "nheight", 37 | "pct_miss", 38 | "n_miss_in_case", 39 | "values", 40 | "n_miss_in_case", 41 | "n_miss_in_var", 42 | "n_vars", 43 | "span_every", 44 | "n_miss_cumsum", 45 | "as.formula", 46 | "complete.cases" 47 | ) 48 | ) 49 | -------------------------------------------------------------------------------- /R/replace-to-na.R: -------------------------------------------------------------------------------- 1 | #' Replace values with missings 2 | #' 3 | #' This function is Defunct, please see [replace_with_na()]. 4 | #' 5 | #' @param ... additional arguments for methods. 6 | #' 7 | #' @return values replaced by NA 8 | #' @export 9 | #' 10 | replace_to_na <- function(...) { 11 | .Defunct("replace_with_na") 12 | } 13 | -------------------------------------------------------------------------------- /R/replace_na_with.R: -------------------------------------------------------------------------------- 1 | #' Replace NA value with provided value 2 | #' 3 | #' This function helps you replace NA values with a single provided value. 4 | #' This can be classed as a kind of imputation, and is powered by 5 | #' [impute_fixed()]. However, we would generally recommend to impute using 6 | #' other model based approaches. See the `simputation` package, for example 7 | #' [simputation::impute_lm()]. See [tidyr::replace_na()] for a slightly 8 | #' different approach, [dplyr::coalesce()] for replacing NAs with values from 9 | #' other vectors, and [dplyr::na_if()] to replace specified values with NA. 10 | #' 11 | #' @param x vector 12 | #' @param value value to replace 13 | #' 14 | #' @return vector with replaced values 15 | #' @export 16 | #' 17 | #' @examples 18 | #' 19 | #' library(naniar) 20 | #' x <- c(1:5, NA, NA, NA) 21 | #' x 22 | #' replace_na_with(x, 0L) 23 | #' replace_na_with(x, "unknown") 24 | #' 25 | #' library(dplyr) 26 | #' dat <- tibble( 27 | #' ones = c(NA,1,1), 28 | #' twos = c(NA,NA, 2), 29 | #' threes = c(NA, NA, NA) 30 | #' ) 31 | #' 32 | #' dat 33 | #' 34 | #' dat %>% 35 | #' mutate( 36 | #' ones = replace_na_with(ones, 0), 37 | #' twos = replace_na_with(twos, -99), 38 | #' threes = replace_na_with(threes, "unknowns") 39 | #' ) 40 | #' 41 | #' dat %>% 42 | #' mutate( 43 | #' across( 44 | #' everything(), 45 | #' \(x) replace_na_with(x, -99) 46 | #' ) 47 | #' ) 48 | #' 49 | replace_na_with <- function(x, value) { 50 | impute_fixed(x, value) 51 | } 52 | -------------------------------------------------------------------------------- /R/set-n-prop-miss.R: -------------------------------------------------------------------------------- 1 | #' Set a proportion or number of missing values 2 | #' 3 | #' @param x vector of values to set missing 4 | #' @param prop proportion of values between 0 and 1 to set as missing 5 | #' 6 | #' @return vector with missing values added 7 | #' @name set-prop-n-miss 8 | #' 9 | #' @examples 10 | #' vec <- rnorm(5) 11 | #' set_prop_miss(vec, 0.2) 12 | #' set_prop_miss(vec, 0.4) 13 | #' set_n_miss(vec, 1) 14 | #' set_n_miss(vec, 4) 15 | #' @export 16 | set_prop_miss <- function(x, prop = 0.1) { 17 | check_is_scalar(prop) 18 | check_btn_0_1(prop) 19 | x[sample(seq_along(x) <= prop * length(x))] <- NA 20 | x 21 | } 22 | 23 | #' @rdname set-prop-n-miss 24 | #' @param n number of values to set missing 25 | #' @export 26 | set_n_miss <- function(x, n = 1) { 27 | check_is_scalar(n) 28 | check_is_integer(n) 29 | x[sample(seq_along(x) <= n)] <- NA 30 | x 31 | } 32 | -------------------------------------------------------------------------------- /R/shadow-shifters.R: -------------------------------------------------------------------------------- 1 | #' Shift missing values to facilitate missing data exploration/visualisation 2 | #' 3 | #' `shadow_shift` transforms missing values to facilitate visualisation, and has 4 | #' different behaviour for different types of variables. For numeric 5 | #' variables, the values are shifted to 10% below the minimum value for a given 6 | #' variable plus some jittered noise, to separate repeated values, so that 7 | #' missing values can be visualised along with the rest of the data. 8 | #' 9 | #' `r lifecycle::badge('deprecated')` 10 | #' 11 | #' @param ... arguments to [impute_below()]. 12 | #' 13 | #' @seealso [add_shadow_shift()] [cast_shadow_shift()] [cast_shadow_shift_label()] 14 | #' 15 | #' @examples 16 | #' airquality$Ozone 17 | #' shadow_shift(airquality$Ozone) 18 | #' \dontrun{ 19 | #' library(dplyr) 20 | #' airquality %>% 21 | #' mutate(Ozone_shift = shadow_shift(Ozone)) 22 | #' } 23 | #' @export 24 | shadow_shift <- function(...) { 25 | lifecycle::deprecate_soft("1.1.0", "shadow_shift()", "impute_below()") 26 | impute_below(...) 27 | } 28 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * local OS X install, R 4.2.2 3 | * github actions testing for devel, release, and ubuntu, windows, and macOSX 4 | 5 | ## R CMD check results 6 | 0 errors | 0 warnings | 1 note 7 | 8 | There were no ERRORs or WARNINGs, and one NOTE: 9 | 10 | ``` 11 | Found the following (possibly) invalid URLs: 12 | URL: https://www.ncei.noaa.gov/products/land-based-station/global-historical-climatology-network-daily 13 | From: inst/doc/special-missing-values.html 14 | Status: Error 15 | Message: Empty reply from server 16 | ``` 17 | 18 | Navigating to the website works on my machine, but I note that the NCEI website states in a banner: 19 | 20 | > Please note: Due to a system outage, many NCEI systems are currently unavailable. We are working to resolve these issues as soon as possible. We apologize for any inconvenience. 21 | 22 | Which makes me think that perhaps this is an issue related to that? 23 | 24 | ## Reverse dependencies 25 | 26 | We checked 6 reverse dependencies (5 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. 27 | 28 | * We saw 0 new problems 29 | * We failed to check 0 packages 30 | 31 | -------------------------------------------------------------------------------- /data-raw/create-data-common-na-numbers.R: -------------------------------------------------------------------------------- 1 | common_na_numbers <- c( 2 | -9, 3 | -99, 4 | -999, 5 | -9999, 6 | 9999, 7 | 66, 8 | 77, 9 | 88 10 | ) 11 | 12 | devtools::use_data(common_na_numbers, overwrite = TRUE) 13 | -------------------------------------------------------------------------------- /data-raw/create-data-common-na-strings.R: -------------------------------------------------------------------------------- 1 | common_na_strings <- c( 2 | "missing", 3 | "NA", 4 | "N A", 5 | "N/A", 6 | "#N/A", 7 | "NA ", 8 | " NA", 9 | "N /A", 10 | "N / A", 11 | " N / A", 12 | "N / A ", 13 | "na", 14 | "n a", 15 | "n/a", 16 | "na ", 17 | " na", 18 | "n /a", 19 | "n / a", 20 | " a / a", 21 | "n / a ", 22 | "NULL", 23 | "null", 24 | "", 25 | "\\?", 26 | "\\*", 27 | "\\." 28 | ) 29 | 30 | usethis::use_data(common_na_strings, overwrite = TRUE) 31 | -------------------------------------------------------------------------------- /data-raw/create-data-oceanbuoys.R: -------------------------------------------------------------------------------- 1 | # modify the tao data from the MissingDataGUI dataset 2 | # library(MissingDataGUI) 3 | library(dplyr) 4 | 5 | # downloaded from https://github.com/chxy/MissingDataGUI/blob/master/data/tao.rda 6 | # as I could not install MissingDataGUI 7 | # load("~/Downloads/tao.rda") 8 | 9 | oceanbuoys <- tao %>% 10 | rename( 11 | sea_temp_c = sea.surface.temp, 12 | air_temp_c = air.temp, 13 | wind_ew = uwind, 14 | wind_ns = vwind 15 | ) %>% 16 | as_tibble() %>% 17 | # convert the factors in a sane way 18 | mutate_if(is.factor, .funs = function(x) as.numeric(as.character(x))) 19 | 20 | devtools::use_data(oceanbuoys, overwrite = TRUE) 21 | # then delete the tao dataset 22 | -------------------------------------------------------------------------------- /data/common_na_numbers.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/data/common_na_numbers.rda -------------------------------------------------------------------------------- /data/common_na_strings.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/data/common_na_strings.rda -------------------------------------------------------------------------------- /data/oceanbuoys.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/data/oceanbuoys.rda -------------------------------------------------------------------------------- /data/pedestrian.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/data/pedestrian.rda -------------------------------------------------------------------------------- /data/riskfactors.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/data/riskfactors.rda -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Article", 2 | title = "Expanding Tidy Data Principles to Facilitate Missing Data Exploration, Visualization and Assessment of Imputations", 3 | author = c(person(given = "Nicholas", family = "Tierney", email = "nicholas.tierney@gmail.com"), 4 | person(given = "Dianne", family = "Cook")), 5 | journal = "Journal of Statistical Software", 6 | year = "2023", 7 | volume = "105", 8 | number = "7", 9 | pages = "1--31", 10 | doi = "10.18637/jss.v105.i07", 11 | header = "To cite naniar in publications use:" 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /man/add_label_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-cols.R 3 | \name{add_label_missings} 4 | \alias{add_label_missings} 5 | \title{Add a column describing if there are any missings in the dataset} 6 | \usage{ 7 | add_label_missings(data, ..., missing = "Missing", complete = "Not Missing") 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{extra variable to label} 13 | 14 | \item{missing}{character a label for when values are missing - defaults to "Missing"} 15 | 16 | \item{complete}{character character a label for when values are complete - defaults to "Not Missing"} 17 | } 18 | \value{ 19 | data.frame with a column "any_missing" that is either "Not Missing" 20 | or "Missing" for the purposes of plotting / exploration / nice print methods 21 | } 22 | \description{ 23 | Add a column describing if there are any missings in the dataset 24 | } 25 | \examples{ 26 | 27 | airquality \%>\% add_label_missings() 28 | airquality \%>\% add_label_missings(Ozone, Solar.R) 29 | airquality \%>\% add_label_missings(Ozone, Solar.R, missing = "yes", complete = "no") 30 | 31 | } 32 | \seealso{ 33 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_n_miss]{add_n_miss()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 34 | } 35 | -------------------------------------------------------------------------------- /man/add_label_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-cols.R 3 | \name{add_label_shadow} 4 | \alias{add_label_shadow} 5 | \title{Add a column describing whether there is a shadow} 6 | \usage{ 7 | add_label_shadow(data, ..., missing = "Missing", complete = "Not Missing") 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{extra variable to label} 13 | 14 | \item{missing}{character a label for when values are missing - defaults to "Missing"} 15 | 16 | \item{complete}{character character a label for when values are complete - defaults to "Not Missing"} 17 | } 18 | \value{ 19 | data.frame with a column, "any_missing", which describes whether or 20 | not there are any rows that have a shadow value. 21 | } 22 | \description{ 23 | Instead of focussing on labelling whether there are missings, we instead 24 | focus on whether there have been any shadows created. This can be useful 25 | when data has been imputed and you need to determine which rows contained 26 | missing values when the shadow was bound to the dataset. 27 | } 28 | \examples{ 29 | 30 | airquality \%>\% 31 | add_shadow(Ozone, Solar.R) \%>\% 32 | add_label_shadow() 33 | 34 | } 35 | \seealso{ 36 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_n_miss]{add_n_miss()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 37 | } 38 | -------------------------------------------------------------------------------- /man/add_n_miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-n-prop-miss.R 3 | \name{add_n_miss} 4 | \alias{add_n_miss} 5 | \title{Add column containing number of missing data values} 6 | \usage{ 7 | add_n_miss(data, ..., label = "n_miss") 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | 12 | \item{...}{Variable names to use instead of the whole dataset. By default this 13 | looks at the whole dataset. Otherwise, this is one or more unquoted 14 | expressions separated by commas. These also respect the dplyr verbs 15 | \code{starts_with}, \code{contains}, \code{ends_with}, etc. By default will add "_all" to 16 | the label if left blank, otherwise will add "_vars" to distinguish that it 17 | has not been used on all of the variables.} 18 | 19 | \item{label}{character default is "n_miss".} 20 | } 21 | \value{ 22 | a dataframe 23 | } 24 | \description{ 25 | It can be useful when doing data analysis to add the number of missing data 26 | points into your dataframe. \code{add_n_miss} adds a column named "n_miss", 27 | which contains the number of missing values in that row. 28 | } 29 | \examples{ 30 | 31 | airquality \%>\% add_n_miss() 32 | airquality \%>\% add_n_miss(Ozone, Solar.R) 33 | airquality \%>\% add_n_miss(dplyr::contains("o")) 34 | 35 | 36 | } 37 | \seealso{ 38 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 39 | } 40 | -------------------------------------------------------------------------------- /man/add_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-cols.R 3 | \name{add_shadow} 4 | \alias{add_shadow} 5 | \title{Add a shadow column to dataframe} 6 | \usage{ 7 | add_shadow(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{One or more unquoted variable names, separated by commas. These also 13 | respect the dplyr verbs \code{starts_with}, \code{contains}, \code{ends_with}, etc.} 14 | } 15 | \value{ 16 | data.frame 17 | } 18 | \description{ 19 | As an alternative to \code{bind_shadow()}, you can add specific individual shadow 20 | columns to a dataset. These also respect the dplyr verbs 21 | \code{starts_with}, \code{contains}, \code{ends_with}, etc. 22 | } 23 | \examples{ 24 | 25 | airquality \%>\% add_shadow(Ozone) 26 | airquality \%>\% add_shadow(Ozone, Solar.R) 27 | 28 | } 29 | \seealso{ 30 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_n_miss]{add_n_miss()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 31 | } 32 | -------------------------------------------------------------------------------- /man/add_shadow_shift.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-cols.R 3 | \name{add_shadow_shift} 4 | \alias{add_shadow_shift} 5 | \title{Add a shadow shifted column to a dataset} 6 | \usage{ 7 | add_shadow_shift(data, ..., suffix = "shift") 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{One or more unquoted variable names separated by commas. These also 13 | respect the dplyr verbs \code{starts_with}, \code{contains}, \code{ends_with}, etc.} 14 | 15 | \item{suffix}{suffix to add to variable, defaults to "shift"} 16 | } 17 | \value{ 18 | data with the added variable shifted named as \code{var_suffix} 19 | } 20 | \description{ 21 | Shadow shift missing values using only the selected variables in a dataset, 22 | by specifying variable names or use dplyr \code{vars} and dplyr verbs 23 | \code{starts_with}, \code{contains}, \code{ends_with}, etc. 24 | } 25 | \examples{ 26 | 27 | airquality \%>\% add_shadow_shift(Ozone, Solar.R) 28 | 29 | } 30 | \seealso{ 31 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_n_miss]{add_n_miss()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/add_span_counter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{add_span_counter} 4 | \alias{add_span_counter} 5 | \title{Add a counter variable for a span of dataframe} 6 | \usage{ 7 | add_span_counter(data, span_size) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{span_size}{integer} 13 | } 14 | \value{ 15 | data.frame with extra variable "span_counter". 16 | } 17 | \description{ 18 | Adds a variable, \code{span_counter} to a dataframe. Used internally to facilitate 19 | counting of missing values over a given span. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | # add_span_counter(pedestrian, span_size = 100) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /man/any_row_miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{any_row_miss} 4 | \alias{any_row_miss} 5 | \title{Helper function to determine whether there are any missings} 6 | \usage{ 7 | any_row_miss(x) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | } 12 | \value{ 13 | logical vector TRUE = missing FALSE = complete 14 | } 15 | \description{ 16 | Helper function to determine whether there are any missings 17 | } 18 | -------------------------------------------------------------------------------- /man/as_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{as_shadow} 4 | \alias{as_shadow} 5 | \title{Create shadows} 6 | \usage{ 7 | as_shadow(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{dataframe} 11 | 12 | \item{...}{selected variables to use} 13 | } 14 | \value{ 15 | appended shadow with column names 16 | } 17 | \description{ 18 | Return a tibble in shadow matrix form, where the variables are the same but 19 | have a suffix _NA attached to distinguish them. 20 | } 21 | \details{ 22 | Representing missing data structure is achieved using the shadow matrix, 23 | introduced in \href{https://www.researchgate.net/publication/2758672_Missing_Data_in_Interactive_High-Dimensional_Data_Visualization}{Swayne and Buja}. The shadow 24 | matrix is the same dimension as the data, and consists of binary indicators 25 | of missingness of data values, where missing is represented as "NA", and not 26 | missing is represented as "!NA". Although these may be represented as 1 and 27 | 0, respectively. 28 | } 29 | \examples{ 30 | 31 | as_shadow(airquality) 32 | } 33 | -------------------------------------------------------------------------------- /man/as_shadow_upset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{as_shadow_upset} 4 | \alias{as_shadow_upset} 5 | \title{Convert data into shadow format for doing an upset plot} 6 | \usage{ 7 | as_shadow_upset(data) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame} 11 | } 12 | \value{ 13 | a data.frame 14 | } 15 | \description{ 16 | Upset plots are a way of visualising common sets, this function transforms 17 | the data into a format that feeds directly into an upset plot 18 | } 19 | \examples{ 20 | 21 | \dontrun{ 22 | 23 | library(UpSetR) 24 | airquality \%>\% 25 | as_shadow_upset() \%>\% 26 | upset() 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/bind_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{bind_shadow} 4 | \alias{bind_shadow} 5 | \title{Bind a shadow dataframe to original data} 6 | \usage{ 7 | bind_shadow(data, only_miss = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | 12 | \item{only_miss}{logical - if FALSE (default) it will bind a dataframe with 13 | all of the variables duplicated with their shadow. Setting this to TRUE 14 | will bind variables only those variables that contain missing values. 15 | See the examples for more details.} 16 | 17 | \item{...}{extra options to pass to \code{\link[=recode_shadow]{recode_shadow()}} - a work in progress.} 18 | } 19 | \value{ 20 | data with the added variable shifted and the suffix \verb{_NA} 21 | } 22 | \description{ 23 | Binding a shadow matrix to a regular dataframe helps visualise and work with 24 | missing data. 25 | } 26 | \examples{ 27 | 28 | bind_shadow(airquality) 29 | 30 | # bind only the variables that contain missing values 31 | bind_shadow(airquality, only_miss = TRUE) 32 | 33 | aq_shadow <- bind_shadow(airquality) 34 | 35 | \dontrun{ 36 | # explore missing data visually 37 | library(ggplot2) 38 | 39 | # using the bounded shadow to visualise Ozone according to whether Solar 40 | # Radiation is missing or not. 41 | 42 | ggplot(data = aq_shadow, 43 | aes(x = Ozone)) + 44 | geom_histogram() + 45 | facet_wrap(~Solar.R_NA, 46 | ncol = 1) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/cast_shadow_shift.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cast-shadows.R 3 | \name{cast_shadow_shift} 4 | \alias{cast_shadow_shift} 5 | \title{Add a shadow and a shadow_shift column to a dataset} 6 | \usage{ 7 | cast_shadow_shift(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{One or more unquoted variable names separated by commas. These 13 | respect the dplyr verbs \code{starts_with}, \code{contains}, \code{ends_with}, etc.} 14 | } 15 | \value{ 16 | data.frame with the shadow and shadow_shift vars 17 | } 18 | \description{ 19 | Shift the values and add a shadow column. It also respects the dplyr 20 | verbs \code{starts_with}, \code{contains}, \code{ends_with}, etc. 21 | } 22 | \examples{ 23 | 24 | airquality \%>\% cast_shadow_shift(Ozone,Temp) 25 | 26 | airquality \%>\% cast_shadow_shift(dplyr::contains("o")) 27 | 28 | } 29 | \seealso{ 30 | \code{\link[=cast_shadow_shift]{cast_shadow_shift()}}, \code{\link[=cast_shadow_shift_label]{cast_shadow_shift_label()}} \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} 31 | } 32 | -------------------------------------------------------------------------------- /man/cast_shadow_shift_label.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cast-shadows.R 3 | \name{cast_shadow_shift_label} 4 | \alias{cast_shadow_shift_label} 5 | \title{Add a shadow column and a shadow shifted column to a dataset} 6 | \usage{ 7 | cast_shadow_shift_label(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{...}{One or more unquoted expressions separated by commas. These also 13 | respect the dplyr verbs "starts_with", "contains", "ends_with", etc.} 14 | } 15 | \value{ 16 | data.frame with the shadow and shadow_shift vars, and missing labels 17 | } 18 | \description{ 19 | Shift the values, add shadow, add missing label 20 | } 21 | \examples{ 22 | 23 | airquality \%>\% cast_shadow_shift_label(Ozone, Solar.R) 24 | 25 | # replicate the plot generated by geom_miss_point() 26 | \dontrun{ 27 | library(ggplot2) 28 | 29 | airquality \%>\% 30 | cast_shadow_shift_label(Ozone,Solar.R) \%>\% 31 | ggplot(aes(x = Ozone_shift, 32 | y = Solar.R_shift, 33 | colour = any_missing)) + 34 | geom_point() 35 | } 36 | 37 | } 38 | \seealso{ 39 | \code{\link[=cast_shadow_shift]{cast_shadow_shift()}}, \code{\link[=cast_shadow_shift_label]{cast_shadow_shift_label()}} \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} 40 | } 41 | -------------------------------------------------------------------------------- /man/common_na_numbers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-common-na-numbers.R 3 | \docType{data} 4 | \name{common_na_numbers} 5 | \alias{common_na_numbers} 6 | \title{Common number values for NA} 7 | \format{ 8 | An object of class \code{numeric} of length 8. 9 | } 10 | \usage{ 11 | common_na_numbers 12 | } 13 | \description{ 14 | This vector contains common number values of NA (missing), which is aimed to 15 | be used inside naniar functions \code{\link[=miss_scan_count]{miss_scan_count()}} and 16 | \code{\link[=replace_with_na]{replace_with_na()}}. The current list of numbers can be found by printing 17 | out \code{common_na_numbers}. It is a useful way to explore your data for 18 | possible missings, but I strongly warn against using this to replace NA 19 | values without very carefully looking at the incidence for each of the 20 | cases. Common NA strings are in the data object \code{common_na_strings}. 21 | } 22 | \note{ 23 | original discussion here \url{https://github.com/njtierney/naniar/issues/168} 24 | } 25 | \examples{ 26 | 27 | dat_ms <- tibble::tribble(~x, ~y, ~z, 28 | 1, "A", -100, 29 | 3, "N/A", -99, 30 | NA, NA, -98, 31 | -99, "E", -101, 32 | -98, "F", -1) 33 | 34 | miss_scan_count(dat_ms, -99) 35 | miss_scan_count(dat_ms, c("-99","-98","N/A")) 36 | common_na_numbers 37 | miss_scan_count(dat_ms, common_na_numbers) 38 | } 39 | \keyword{datasets} 40 | -------------------------------------------------------------------------------- /man/draw_key.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/legend-draw.R 3 | \name{draw_key} 4 | \alias{draw_key} 5 | \alias{draw_key_missing_point} 6 | \title{Key drawing functions} 7 | \usage{ 8 | draw_key_missing_point(data, params, size) 9 | } 10 | \arguments{ 11 | \item{data}{A single row data frame containing the scaled aesthetics to 12 | display in this key} 13 | 14 | \item{params}{A list of additional parameters supplied to the geom.} 15 | 16 | \item{size}{Width and height of key in mm.} 17 | } 18 | \value{ 19 | A grid grob. 20 | } 21 | \description{ 22 | Each Geom has an associated function that draws the key when the geom needs 23 | to be displayed in a legend. These are the options built into naniar. 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/figures/README-facet-by-month-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-facet-by-month-1.png -------------------------------------------------------------------------------- /man/figures/README-geom-miss-point-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-geom-miss-point-1.png -------------------------------------------------------------------------------- /man/figures/README-geom-missing-point-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-geom-missing-point-1.png -------------------------------------------------------------------------------- /man/figures/README-gg-miss-span-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-gg-miss-span-1.png -------------------------------------------------------------------------------- /man/figures/README-gg-miss-upset-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-gg-miss-upset-1.png -------------------------------------------------------------------------------- /man/figures/README-gg-miss-var-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-gg-miss-var-1.png -------------------------------------------------------------------------------- /man/figures/README-gg-missing-var-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-gg-missing-var-1.png -------------------------------------------------------------------------------- /man/figures/README-regular-geom-point-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-regular-geom-point-1.png -------------------------------------------------------------------------------- /man/figures/README-shadow-impute-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-shadow-impute-1.png -------------------------------------------------------------------------------- /man/figures/README-shadow-w-ggplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-shadow-w-ggplot-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-upset-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/README-upset-plot-1.png -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/naniar-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/man/figures/naniar-logo.png -------------------------------------------------------------------------------- /man/gather_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{gather_shadow} 4 | \alias{gather_shadow} 5 | \title{Long form representation of a shadow matrix} 6 | \usage{ 7 | gather_shadow(data) 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | } 12 | \value{ 13 | dataframe in long, format, containing information about the missings 14 | } 15 | \description{ 16 | \code{gather_shadow} is a long-form representation of binding the shadow matrix to 17 | your data, producing variables named \code{case}, \code{variable}, and \code{missing}, where 18 | \code{missing} contains the missing value representation. 19 | } 20 | \examples{ 21 | 22 | gather_shadow(airquality) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/gg_miss_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-case.R 3 | \name{gg_miss_case} 4 | \alias{gg_miss_case} 5 | \title{Plot the number of missings per case (row)} 6 | \usage{ 7 | gg_miss_case(x, facet, order_cases = TRUE, show_pct = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{data.frame} 11 | 12 | \item{facet}{(optional) a single bare variable name, if you want to create a faceted plot.} 13 | 14 | \item{order_cases}{logical Order the rows by missingness (default is FALSE - 15 | no order).} 16 | 17 | \item{show_pct}{logical Show the percentage of cases} 18 | } 19 | \value{ 20 | a ggplot object depicting the number of missings in a given case. 21 | } 22 | \description{ 23 | This is a visual analogue to \code{miss_case_summary}. It draws a ggplot of the 24 | number of missings in each case (row). A default minimal theme is used, which 25 | can be customised as normal for ggplot. 26 | } 27 | \examples{ 28 | 29 | gg_miss_case(airquality) 30 | \dontrun{ 31 | library(ggplot2) 32 | gg_miss_case(airquality) + labs(x = "Number of Cases") 33 | gg_miss_case(airquality, show_pct = TRUE) 34 | gg_miss_case(airquality, order_cases = FALSE) 35 | gg_miss_case(airquality, facet = Month) 36 | gg_miss_case(airquality, facet = Month, order_cases = FALSE) 37 | gg_miss_case(airquality, facet = Month, show_pct = TRUE) 38 | } 39 | } 40 | \seealso{ 41 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case_cumsum]{gg_miss_case_cumsum()}} \code{\link[=gg_miss_fct]{gg_miss_fct()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_var_cumsum]{gg_miss_var_cumsum()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 42 | } 43 | -------------------------------------------------------------------------------- /man/gg_miss_case_cumsum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-case-cumsum.R 3 | \name{gg_miss_case_cumsum} 4 | \alias{gg_miss_case_cumsum} 5 | \title{Plot of cumulative sum of missing for cases} 6 | \usage{ 7 | gg_miss_case_cumsum(x, breaks = 20) 8 | } 9 | \arguments{ 10 | \item{x}{a dataframe} 11 | 12 | \item{breaks}{the breaks for the x axis default is 20} 13 | } 14 | \value{ 15 | a ggplot object depicting the number of missings 16 | } 17 | \description{ 18 | A plot showing the cumulative sum of missing values for cases, reading the 19 | rows from the top to bottom. A default minimal theme is used, which can be 20 | customised as normal for ggplot. 21 | } 22 | \examples{ 23 | 24 | gg_miss_case_cumsum(airquality) 25 | } 26 | \seealso{ 27 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case]{gg_miss_case()}} \code{\link[=gg_miss_fct]{gg_miss_fct()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_var_cumsum]{gg_miss_var_cumsum()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 28 | } 29 | -------------------------------------------------------------------------------- /man/gg_miss_fct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-fct.R 3 | \name{gg_miss_fct} 4 | \alias{gg_miss_fct} 5 | \title{Plot the number of missings for each variable, broken down by a factor} 6 | \usage{ 7 | gg_miss_fct(x, fct) 8 | } 9 | \arguments{ 10 | \item{x}{data.frame} 11 | 12 | \item{fct}{column containing the factor variable to visualise} 13 | } 14 | \value{ 15 | ggplot object depicting the \% missing of each factor level for 16 | each variable. 17 | } 18 | \description{ 19 | This function draws a ggplot plot of the number of missings in each column, 20 | broken down by a categorical variable from the dataset. A default minimal 21 | theme is used, which can be customised as normal for ggplot. 22 | } 23 | \examples{ 24 | 25 | gg_miss_fct(x = riskfactors, fct = marital) 26 | \dontrun{ 27 | library(ggplot2) 28 | gg_miss_fct(x = riskfactors, fct = marital) + labs(title = "NA in Risk Factors and Marital status") 29 | } 30 | 31 | } 32 | \seealso{ 33 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case]{gg_miss_case()}} \code{\link[=gg_miss_case_cumsum]{gg_miss_case_cumsum()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_var_cumsum]{gg_miss_var_cumsum()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 34 | } 35 | -------------------------------------------------------------------------------- /man/gg_miss_upset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-upset.R 3 | \name{gg_miss_upset} 4 | \alias{gg_miss_upset} 5 | \title{Plot the pattern of missingness using an upset plot.} 6 | \usage{ 7 | gg_miss_upset(data, order.by = "freq", ...) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{order.by}{(from UpSetR::upset) How the intersections in the matrix should be ordered by. Options include frequency (entered as "freq"), degree, or both in any order. See \code{?UpSetR::upset} for more options} 13 | 14 | \item{...}{arguments to pass to upset plot - see \code{?UpSetR::upset}} 15 | } 16 | \value{ 17 | a ggplot visualisation of missing data 18 | } 19 | \description{ 20 | Upset plots are a way of visualising common sets, \code{gg_miss_upset} shows the 21 | number of missing values for each of the sets of data. The default option 22 | of \code{gg_miss_upset} is taken from \code{UpSetR::upset} - which is to use up to 5 23 | sets and up to 40 interactions. We also set the ordering to by the 24 | frequency of the intersections. Setting \code{nsets = 5} means to look at 5 25 | variables and their combinations. The number of combinations or rather 26 | \code{intersections} is controlled by \code{nintersects}. If there are 40 27 | intersections, there will be 40 combinations of variables explored. The 28 | number of sets and intersections can be changed by passing arguments \code{nsets = 10} to look at 10 sets of variables, and \code{nintersects = 50} to look at 50 29 | intersections. 30 | } 31 | \examples{ 32 | 33 | \dontrun{ 34 | gg_miss_upset(airquality) 35 | gg_miss_upset(riskfactors) 36 | gg_miss_upset(riskfactors, nsets = 10) 37 | gg_miss_upset(riskfactors, nsets = 10, nintersects = 10) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /man/gg_miss_var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-var.R 3 | \name{gg_miss_var} 4 | \alias{gg_miss_var} 5 | \title{Plot the number of missings for each variable} 6 | \usage{ 7 | gg_miss_var(x, facet, show_pct = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{a dataframe} 11 | 12 | \item{facet}{(optional) bare variable name, if you want to create a faceted plot.} 13 | 14 | \item{show_pct}{logical shows the number of missings (default), but if set to 15 | TRUE, it will display the proportion of missings.} 16 | } 17 | \value{ 18 | a ggplot object depicting the number of missings in a given column 19 | } 20 | \description{ 21 | This is a visual analogue to \code{miss_var_summary}. It draws a ggplot of the 22 | number of missings in each variable, ordered to show which variables have 23 | the most missing data. A default minimal theme is used, which can be 24 | customised as normal for ggplot. 25 | } 26 | \examples{ 27 | 28 | gg_miss_var(airquality) 29 | \dontrun{ 30 | library(ggplot2) 31 | gg_miss_var(airquality) + labs(y = "Look at all the missing ones") 32 | gg_miss_var(airquality, Month) 33 | gg_miss_var(airquality, Month, show_pct = TRUE) 34 | gg_miss_var(airquality, Month, show_pct = TRUE) + ylim(0, 100) 35 | } 36 | } 37 | \seealso{ 38 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case]{gg_miss_case()}} \code{\link[=gg_miss_case_cumsum]{gg_miss_case_cumsum()}} \code{\link[=gg_miss_fct]{gg_miss_fct()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_var_cumsum]{gg_miss_var_cumsum()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 39 | } 40 | -------------------------------------------------------------------------------- /man/gg_miss_var_cumsum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-var-cumsum.R 3 | \name{gg_miss_var_cumsum} 4 | \alias{gg_miss_var_cumsum} 5 | \title{Plot of cumulative sum of missing value for each variable} 6 | \usage{ 7 | gg_miss_var_cumsum(x) 8 | } 9 | \arguments{ 10 | \item{x}{a data.frame} 11 | } 12 | \value{ 13 | a ggplot object showing the cumulative sum of missings over the variables 14 | } 15 | \description{ 16 | A plot showing the cumulative sum of missing values for each variable, 17 | reading columns from the left to the right of the initial dataframe. A 18 | default minimal theme is used, which can be customised as normal for ggplot. 19 | } 20 | \examples{ 21 | 22 | gg_miss_var_cumsum(airquality) 23 | } 24 | \seealso{ 25 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case]{gg_miss_case()}} \code{\link[=gg_miss_case_cumsum]{gg_miss_case_cumsum()}} \code{\link[=gg_miss_fct]{gg_miss_fct()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 26 | } 27 | -------------------------------------------------------------------------------- /man/gg_miss_which.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg-miss-which.R 3 | \name{gg_miss_which} 4 | \alias{gg_miss_which} 5 | \title{Plot which variables contain a missing value} 6 | \usage{ 7 | gg_miss_which(x) 8 | } 9 | \arguments{ 10 | \item{x}{a dataframe} 11 | } 12 | \value{ 13 | a ggplot object of which variables contains missing values 14 | } 15 | \description{ 16 | This plot produces a set of rectangles indicating whether there is a missing 17 | element in a column or not. A default minimal theme is used, which can be 18 | customised as normal for ggplot. 19 | } 20 | \examples{ 21 | 22 | gg_miss_which(airquality) 23 | } 24 | \seealso{ 25 | \code{\link[=geom_miss_point]{geom_miss_point()}} \code{\link[=gg_miss_case]{gg_miss_case()}} \code{\link[=gg_miss_case_cumsum]{gg_miss_case_cumsum()}} \code{\link[=gg_miss_fct]{gg_miss_fct()}} \code{\link[=gg_miss_span]{gg_miss_span()}} \code{\link[=gg_miss_var]{gg_miss_var()}} \code{\link[=gg_miss_var_cumsum]{gg_miss_var_cumsum()}} \code{\link[=gg_miss_which]{gg_miss_which()}} 26 | } 27 | -------------------------------------------------------------------------------- /man/impute_below.numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute_below.R 3 | \name{impute_below.numeric} 4 | \alias{impute_below.numeric} 5 | \title{Impute numeric values below a range for graphical exploration} 6 | \usage{ 7 | \method{impute_below}{numeric}( 8 | x, 9 | prop_below = 0.1, 10 | jitter = 0.05, 11 | seed_shift = 2017 - 7 - 1 - 1850, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{a variable of interest to shift} 17 | 18 | \item{prop_below}{the degree to shift the values. default is} 19 | 20 | \item{jitter}{the amount of jitter to add. default is 0.05} 21 | 22 | \item{seed_shift}{a random seed to set, if you like} 23 | 24 | \item{...}{extra arguments to pass} 25 | } 26 | \description{ 27 | Impute numeric values below a range for graphical exploration 28 | } 29 | -------------------------------------------------------------------------------- /man/impute_below_if.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute_below.R 3 | \name{impute_below_if} 4 | \alias{impute_below_if} 5 | \title{Scoped variants of \code{impute_below}} 6 | \usage{ 7 | impute_below_if(.tbl, .predicate, prop_below = 0.1, jitter = 0.05, ...) 8 | } 9 | \arguments{ 10 | \item{.tbl}{data.frame} 11 | 12 | \item{.predicate}{A predicate function (such as is.numeric)} 13 | 14 | \item{prop_below}{the degree to shift the values. default is} 15 | 16 | \item{jitter}{the amount of jitter to add. default is 0.05} 17 | 18 | \item{...}{extra arguments} 19 | } 20 | \value{ 21 | an dataset with values imputed 22 | } 23 | \description{ 24 | \code{impute_below} operates on all variables. To only impute variables 25 | that satisfy a specific condition, use the scoped variants, 26 | \code{impute_below_at}, and \code{impute_below_if}. 27 | } 28 | \examples{ 29 | 30 | airquality \%>\% 31 | impute_below_if(.predicate = is.numeric) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/impute_factor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute-factor.R 3 | \name{impute_factor} 4 | \alias{impute_factor} 5 | \alias{impute_factor.default} 6 | \alias{impute_factor.factor} 7 | \alias{impute_factor.character} 8 | \alias{impute_factor.shade} 9 | \title{Impute a factor value into a vector with missing values} 10 | \usage{ 11 | impute_factor(x, value) 12 | 13 | \method{impute_factor}{default}(x, value) 14 | 15 | \method{impute_factor}{factor}(x, value) 16 | 17 | \method{impute_factor}{character}(x, value) 18 | 19 | \method{impute_factor}{shade}(x, value) 20 | } 21 | \arguments{ 22 | \item{x}{vector} 23 | 24 | \item{value}{factor to impute} 25 | } 26 | \value{ 27 | vector with a factor values replaced 28 | } 29 | \description{ 30 | For imputing fixed factor levels. It adds the new imputed value to the end 31 | of the levels of the vector. We generally recommend to impute using other 32 | model based approaches. See the \code{simputation} package, for example 33 | \code{\link[simputation:impute_lm]{simputation::impute_lm()}}. 34 | } 35 | \examples{ 36 | 37 | vec <- factor(LETTERS[1:10]) 38 | 39 | vec[sample(1:10, 3)] <- NA 40 | 41 | vec 42 | 43 | impute_factor(vec, "wat") 44 | 45 | library(dplyr) 46 | 47 | dat <- tibble( 48 | num = rnorm(10), 49 | int = rpois(10, 5), 50 | fct = factor(LETTERS[1:10]) 51 | ) \%>\% 52 | mutate( 53 | across( 54 | everything(), 55 | \(x) set_prop_miss(x, prop = 0.25) 56 | ) 57 | ) 58 | 59 | dat 60 | 61 | dat \%>\% 62 | nabular() \%>\% 63 | mutate( 64 | num = impute_fixed(num, -9999), 65 | int = impute_zero(int), 66 | fct = impute_factor(fct, "out") 67 | ) 68 | 69 | } 70 | -------------------------------------------------------------------------------- /man/impute_fixed.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute-fixed.R 3 | \name{impute_fixed} 4 | \alias{impute_fixed} 5 | \alias{impute_fixed.default} 6 | \title{Impute a fixed value into a vector with missing values} 7 | \usage{ 8 | impute_fixed(x, value) 9 | 10 | \method{impute_fixed}{default}(x, value) 11 | } 12 | \arguments{ 13 | \item{x}{vector} 14 | 15 | \item{value}{value to impute} 16 | } 17 | \value{ 18 | vector with a fixed values replaced 19 | } 20 | \description{ 21 | This can be useful if you are imputing specific values, however we would 22 | generally recommend to impute using other model based approaches. See 23 | the \code{simputation} package, for example \code{\link[simputation:impute_lm]{simputation::impute_lm()}}. 24 | } 25 | \examples{ 26 | 27 | vec <- rnorm(10) 28 | 29 | vec[sample(1:10, 3)] <- NA 30 | 31 | vec 32 | 33 | impute_fixed(vec, -999) 34 | 35 | library(dplyr) 36 | 37 | dat <- tibble( 38 | num = rnorm(10), 39 | int = rpois(10, 5), 40 | fct = factor(LETTERS[1:10]) 41 | ) \%>\% 42 | mutate( 43 | across( 44 | everything(), 45 | \(x) set_prop_miss(x, prop = 0.25) 46 | ) 47 | ) 48 | 49 | dat 50 | 51 | dat \%>\% 52 | nabular() \%>\% 53 | mutate( 54 | num = impute_fixed(num, -9999), 55 | int = impute_zero(int), 56 | fct = impute_factor(fct, "out") 57 | ) 58 | 59 | } 60 | -------------------------------------------------------------------------------- /man/impute_mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute_mean.R 3 | \name{impute_mean} 4 | \alias{impute_mean} 5 | \alias{impute_mean.default} 6 | \alias{impute_mean.factor} 7 | \title{Impute the mean value into a vector with missing values} 8 | \usage{ 9 | impute_mean(x) 10 | 11 | \method{impute_mean}{default}(x) 12 | 13 | \method{impute_mean}{factor}(x) 14 | } 15 | \arguments{ 16 | \item{x}{vector} 17 | } 18 | \value{ 19 | vector with mean values replaced 20 | } 21 | \description{ 22 | This can be useful if you are imputing specific values, however we would 23 | generally recommend to impute using other model based approaches. See 24 | the \code{simputation} package, for example \code{\link[simputation:impute_lm]{simputation::impute_lm()}}. 25 | } 26 | \examples{ 27 | 28 | library(dplyr) 29 | vec <- rnorm(10) 30 | 31 | vec[sample(1:10, 3)] <- NA 32 | 33 | impute_mean(vec) 34 | 35 | dat <- tibble( 36 | num = rnorm(10), 37 | int = as.integer(rpois(10, 5)), 38 | fct = factor(LETTERS[1:10]) 39 | ) \%>\% 40 | mutate( 41 | across( 42 | everything(), 43 | \(x) set_prop_miss(x, prop = 0.25) 44 | ) 45 | ) 46 | 47 | dat 48 | 49 | dat \%>\% 50 | nabular() \%>\% 51 | mutate( 52 | num = impute_mean(num), 53 | int = impute_mean(int), 54 | fct = impute_mean(fct), 55 | ) 56 | 57 | dat \%>\% 58 | nabular() \%>\% 59 | mutate( 60 | across( 61 | where(is.numeric), 62 | impute_mean 63 | ) 64 | ) 65 | 66 | dat \%>\% 67 | nabular() \%>\% 68 | mutate( 69 | across( 70 | c("num", "int"), 71 | impute_mean 72 | ) 73 | ) 74 | 75 | } 76 | -------------------------------------------------------------------------------- /man/impute_median.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute-median.R 3 | \name{impute_median} 4 | \alias{impute_median} 5 | \alias{impute_median.default} 6 | \alias{impute_median.factor} 7 | \title{Impute the median value into a vector with missing values} 8 | \usage{ 9 | impute_median(x) 10 | 11 | \method{impute_median}{default}(x) 12 | 13 | \method{impute_median}{factor}(x) 14 | } 15 | \arguments{ 16 | \item{x}{vector} 17 | } 18 | \value{ 19 | vector with median values replaced 20 | } 21 | \description{ 22 | Impute the median value into a vector with missing values 23 | } 24 | \examples{ 25 | 26 | vec <- rnorm(10) 27 | 28 | vec[sample(1:10, 3)] <- NA 29 | 30 | impute_median(vec) 31 | 32 | library(dplyr) 33 | 34 | dat <- tibble( 35 | num = rnorm(10), 36 | int = as.integer(rpois(10, 5)), 37 | fct = factor(LETTERS[1:10]) 38 | ) \%>\% 39 | mutate( 40 | across( 41 | everything(), 42 | \(x) set_prop_miss(x, prop = 0.25) 43 | ) 44 | ) 45 | 46 | dat 47 | 48 | dat \%>\% 49 | nabular() \%>\% 50 | mutate( 51 | num = impute_median(num), 52 | int = impute_median(int), 53 | ) 54 | 55 | dat \%>\% 56 | nabular() \%>\% 57 | mutate( 58 | across( 59 | where(is.numeric), 60 | impute_median 61 | ) 62 | ) 63 | 64 | dat \%>\% 65 | nabular() \%>\% 66 | mutate( 67 | across( 68 | c("num", "int"), 69 | impute_median 70 | ) 71 | ) 72 | 73 | } 74 | -------------------------------------------------------------------------------- /man/impute_mode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute-mode.R 3 | \name{impute_mode} 4 | \alias{impute_mode} 5 | \alias{impute_mode.default} 6 | \alias{impute_mode.integer} 7 | \alias{impute_mode.factor} 8 | \title{Impute the mode value into a vector with missing values} 9 | \usage{ 10 | impute_mode(x) 11 | 12 | \method{impute_mode}{default}(x) 13 | 14 | \method{impute_mode}{integer}(x) 15 | 16 | \method{impute_mode}{factor}(x) 17 | } 18 | \arguments{ 19 | \item{x}{vector 20 | 21 | This approach adapts examples provided \href{https://stackoverflow.com/questions/2547402/how-to-find-the-statistical-mode}{from stack overflow}, and for the integer 22 | case, just rounds the value. While this can be useful if you are 23 | imputing specific values, however we would generally recommend to impute 24 | using other model based approaches. See the \code{simputation} package, for 25 | example \code{\link[simputation:impute_lm]{simputation::impute_lm()}}.} 26 | } 27 | \value{ 28 | vector with mode values replaced 29 | } 30 | \description{ 31 | Impute the mode value into a vector with missing values 32 | } 33 | \examples{ 34 | 35 | vec <- rnorm(10) 36 | 37 | vec[sample(1:10, 3)] <- NA 38 | 39 | impute_mode(vec) 40 | 41 | library(dplyr) 42 | 43 | dat <- tibble( 44 | num = rnorm(10), 45 | int = rpois(10, 5), 46 | fct = factor(LETTERS[1:10]) 47 | ) \%>\% 48 | mutate( 49 | across( 50 | everything(), 51 | \(x) set_prop_miss(x, prop = 0.25) 52 | ) 53 | ) 54 | 55 | dat 56 | 57 | 58 | dat \%>\% 59 | nabular() \%>\% 60 | mutate( 61 | num = impute_mode(num), 62 | int = impute_mode(int), 63 | fct = impute_mode(fct) 64 | ) 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/impute_zero.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/impute-zero.R 3 | \name{impute_zero} 4 | \alias{impute_zero} 5 | \title{Impute zero into a vector with missing values} 6 | \usage{ 7 | impute_zero(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector} 11 | } 12 | \value{ 13 | vector with a fixed values replaced 14 | } 15 | \description{ 16 | This can be useful if you are imputing specific values, however we would 17 | generally recommend to impute using other model based approaches. See 18 | the \code{simputation} package, for example \code{\link[simputation:impute_lm]{simputation::impute_lm()}}. 19 | } 20 | \examples{ 21 | 22 | vec <- rnorm(10) 23 | 24 | vec[sample(1:10, 3)] <- NA 25 | 26 | vec 27 | 28 | impute_zero(vec) 29 | 30 | library(dplyr) 31 | 32 | dat <- tibble( 33 | num = rnorm(10), 34 | int = rpois(10, 5), 35 | fct = factor(LETTERS[1:10]) 36 | ) \%>\% 37 | mutate( 38 | across( 39 | everything(), 40 | \(x) set_prop_miss(x, prop = 0.25) 41 | ) 42 | ) 43 | 44 | dat 45 | 46 | dat \%>\% 47 | nabular() \%>\% 48 | mutate( 49 | num = impute_fixed(num, -9999), 50 | int = impute_zero(int), 51 | fct = impute_factor(fct, "out") 52 | ) 53 | 54 | } 55 | -------------------------------------------------------------------------------- /man/is_shade.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shade.R 3 | \name{is_shade} 4 | \alias{is_shade} 5 | \alias{are_shade} 6 | \alias{any_shade} 7 | \title{Detect if this is a shade} 8 | \usage{ 9 | is_shade(x) 10 | 11 | are_shade(x) 12 | 13 | any_shade(x) 14 | } 15 | \arguments{ 16 | \item{x}{a vector you want to test if is a shade} 17 | } 18 | \value{ 19 | logical - is this a shade? 20 | } 21 | \description{ 22 | This tells us if this column is a shade 23 | } 24 | \examples{ 25 | 26 | xs <- shade(c(NA, 1, 2, "3")) 27 | 28 | is_shade(xs) 29 | are_shade(xs) 30 | any_shade(xs) 31 | 32 | aq_s <- as_shadow(airquality) 33 | 34 | is_shade(aq_s) 35 | are_shade(aq_s) 36 | any_shade(aq_s) 37 | any_shade(airquality) 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/label_miss_1d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/label-miss.R 3 | \name{label_miss_1d} 4 | \alias{label_miss_1d} 5 | \title{Label a missing from one column} 6 | \usage{ 7 | label_miss_1d(x1) 8 | } 9 | \arguments{ 10 | \item{x1}{a variable of a dataframe} 11 | } 12 | \value{ 13 | a vector indicating whether any of these rows had missing values 14 | } 15 | \description{ 16 | Label whether a value is missing in a row of one columns. 17 | } 18 | \note{ 19 | can we generalise label_miss to work for any number of variables? 20 | } 21 | \examples{ 22 | 23 | label_miss_1d(airquality$Ozone) 24 | 25 | } 26 | \seealso{ 27 | \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} 28 | } 29 | -------------------------------------------------------------------------------- /man/label_miss_2d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/label-miss.R 3 | \name{label_miss_2d} 4 | \alias{label_miss_2d} 5 | \title{label_miss_2d} 6 | \usage{ 7 | label_miss_2d(x1, x2) 8 | } 9 | \arguments{ 10 | \item{x1}{a variable of a dataframe} 11 | 12 | \item{x2}{another variable of a dataframe} 13 | } 14 | \value{ 15 | a vector indicating whether any of these rows had missing values 16 | } 17 | \description{ 18 | Label whether a value is missing in either row of two columns. 19 | } 20 | \examples{ 21 | 22 | label_miss_2d(airquality$Ozone, airquality$Solar.R) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/label_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add-cols.R 3 | \name{label_missings} 4 | \alias{label_missings} 5 | \title{Is there a missing value in the row of a dataframe?} 6 | \usage{ 7 | label_missings(data, ..., missing = "Missing", complete = "Not Missing") 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe or set of vectors of the same length} 11 | 12 | \item{...}{extra variable to label} 13 | 14 | \item{missing}{character a label for when values are missing - defaults to "Missing"} 15 | 16 | \item{complete}{character character a label for when values are complete - defaults to "Not Missing"} 17 | } 18 | \value{ 19 | character vector of "Missing" and "Not Missing". 20 | } 21 | \description{ 22 | Creates a character vector describing presence/absence of missing values 23 | } 24 | \examples{ 25 | 26 | label_missings(airquality) 27 | 28 | \dontrun{ 29 | library(dplyr) 30 | 31 | airquality \%>\% 32 | mutate(is_missing = label_missings(airquality)) \%>\% 33 | head() 34 | 35 | airquality \%>\% 36 | mutate(is_missing = label_missings(airquality, 37 | missing = "definitely missing", 38 | complete = "absolutely complete")) \%>\% 39 | head() 40 | } 41 | } 42 | \seealso{ 43 | \code{\link[=bind_shadow]{bind_shadow()}} \code{\link[=add_any_miss]{add_any_miss()}} \code{\link[=add_label_missings]{add_label_missings()}} \code{\link[=add_label_shadow]{add_label_shadow()}} \code{\link[=add_miss_cluster]{add_miss_cluster()}} \code{\link[=add_n_miss]{add_n_miss()}} \code{\link[=add_prop_miss]{add_prop_miss()}} \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow]{cast_shadow()}} 44 | } 45 | -------------------------------------------------------------------------------- /man/miss-pct-prop-defunct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miss-complete-x-pct-prop.R 3 | \name{miss-pct-prop-defunct} 4 | \alias{miss-pct-prop-defunct} 5 | \alias{miss_var_prop} 6 | \alias{complete_var_prop} 7 | \alias{miss_var_pct} 8 | \alias{complete_var_pct} 9 | \alias{miss_case_prop} 10 | \alias{complete_case_prop} 11 | \alias{miss_case_pct} 12 | \alias{complete_case_pct} 13 | \title{Proportion of variables containing missings or complete values} 14 | \usage{ 15 | miss_var_prop(...) 16 | 17 | complete_var_prop(...) 18 | 19 | miss_var_pct(...) 20 | 21 | complete_var_pct(...) 22 | 23 | miss_case_prop(...) 24 | 25 | complete_case_prop(...) 26 | 27 | miss_case_pct(...) 28 | 29 | complete_case_pct(...) 30 | } 31 | \arguments{ 32 | \item{...}{arguments} 33 | } 34 | \description{ 35 | Defunct. Please see \code{\link[=prop_miss_var]{prop_miss_var()}}, \code{\link[=prop_complete_var]{prop_complete_var()}}, \code{\link[=pct_miss_var]{pct_miss_var()}}, \code{\link[=pct_complete_var]{pct_complete_var()}}, \code{\link[=prop_miss_case]{prop_miss_case()}}, \code{\link[=prop_complete_case]{prop_complete_case()}}, \code{\link[=pct_miss_case]{pct_miss_case()}}, \code{\link[=pct_complete_case]{pct_complete_case()}}. 36 | } 37 | -------------------------------------------------------------------------------- /man/miss_case_cumsum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miss-x-cumsum.R 3 | \name{miss_case_cumsum} 4 | \alias{miss_case_cumsum} 5 | \title{Summarise the missingness in each case} 6 | \usage{ 7 | miss_case_cumsum(data) 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | } 12 | \value{ 13 | a tibble containing the number and percent of missing data in each 14 | case 15 | 16 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 17 | } 18 | \description{ 19 | Provide a data.frame containing each case (row), the number and percent of 20 | missing values in each case. 21 | } 22 | \examples{ 23 | 24 | miss_case_cumsum(airquality) 25 | 26 | \dontrun{ 27 | library(dplyr) 28 | 29 | airquality \%>\% 30 | group_by(Month) \%>\% 31 | miss_case_cumsum() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/miss_prop_summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miss-prop-pct-summary.R 3 | \name{miss_prop_summary} 4 | \alias{miss_prop_summary} 5 | \title{Proportions of missings in data, variables, and cases.} 6 | \usage{ 7 | miss_prop_summary(data) 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | } 12 | \value{ 13 | a dataframe 14 | } 15 | \description{ 16 | Return missing data info about the dataframe, the variables, and the cases. 17 | Specifically, returning how many elements in a dataframe contain a missing 18 | value, how many elements in a variable contain a missing value, and how many 19 | elements in a case contain a missing. 20 | } 21 | \examples{ 22 | 23 | miss_prop_summary(airquality) 24 | \dontrun{ 25 | library(dplyr) 26 | # respects dplyr::group_by 27 | airquality \%>\% group_by(Month) \%>\% miss_prop_summary() 28 | } 29 | 30 | } 31 | \seealso{ 32 | \code{\link[=pct_miss_case]{pct_miss_case()}} \code{\link[=prop_miss_case]{prop_miss_case()}} \code{\link[=pct_miss_var]{pct_miss_var()}} \code{\link[=prop_miss_var]{prop_miss_var()}} \code{\link[=pct_complete_case]{pct_complete_case()}} \code{\link[=prop_complete_case]{prop_complete_case()}} \code{\link[=pct_complete_var]{pct_complete_var()}} \code{\link[=prop_complete_var]{prop_complete_var()}} \code{\link[=miss_prop_summary]{miss_prop_summary()}} \code{\link[=miss_case_summary]{miss_case_summary()}} \code{\link[=miss_case_table]{miss_case_table()}} \code{\link[=miss_summary]{miss_summary()}} \code{\link[=miss_var_run]{miss_var_run()}} \code{\link[=miss_var_span]{miss_var_span()}} \code{\link[=miss_var_summary]{miss_var_summary()}} \code{\link[=miss_var_table]{miss_var_table()}} 33 | } 34 | -------------------------------------------------------------------------------- /man/miss_var_which.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/where-na.R 3 | \name{miss_var_which} 4 | \alias{miss_var_which} 5 | \title{Which variables contain missing values?} 6 | \usage{ 7 | miss_var_which(data) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame} 11 | } 12 | \value{ 13 | character vector of variable names 14 | } 15 | \description{ 16 | It can be helpful when writing other functions to just return the names 17 | of the variables that contain missing values. \code{miss_var_which} returns a 18 | vector of variable names that contain missings. It will return NULL when 19 | there are no missings. 20 | } 21 | \examples{ 22 | miss_var_which(airquality) 23 | 24 | miss_var_which(mtcars) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/n-var-case-complete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-var-miss.R 3 | \name{n-var-case-complete} 4 | \alias{n-var-case-complete} 5 | \alias{n_var_complete} 6 | \alias{n_case_complete} 7 | \title{The number of variables with complete values} 8 | \usage{ 9 | n_var_complete(data) 10 | 11 | n_case_complete(data) 12 | } 13 | \arguments{ 14 | \item{data}{data.frame} 15 | } 16 | \value{ 17 | integer number of complete values 18 | } 19 | \description{ 20 | This function calculates the number of variables that contain a complete value 21 | } 22 | \examples{ 23 | 24 | # how many variables contain complete values? 25 | n_var_complete(airquality) 26 | n_case_complete(airquality) 27 | 28 | } 29 | \seealso{ 30 | \code{\link[=n_var_miss]{n_var_miss()}} 31 | } 32 | -------------------------------------------------------------------------------- /man/n-var-case-miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-var-miss.R 3 | \name{n-var-case-miss} 4 | \alias{n-var-case-miss} 5 | \alias{n_var_miss} 6 | \alias{n_case_miss} 7 | \title{The number of variables or cases with missing values} 8 | \usage{ 9 | n_var_miss(data) 10 | 11 | n_case_miss(data) 12 | } 13 | \arguments{ 14 | \item{data}{data.frame} 15 | } 16 | \value{ 17 | integer, number of missings 18 | } 19 | \description{ 20 | This function calculates the number of variables or cases that contain a missing value 21 | } 22 | \examples{ 23 | # how many variables contain missing values? 24 | n_var_miss(airquality) 25 | n_case_miss(airquality) 26 | 27 | } 28 | \seealso{ 29 | \code{\link[=n_var_complete]{n_var_complete()}} 30 | } 31 | -------------------------------------------------------------------------------- /man/n_complete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{n_complete} 4 | \alias{n_complete} 5 | \title{Return the number of complete values} 6 | \usage{ 7 | n_complete(x) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | } 12 | \value{ 13 | numeric number of complete values 14 | } 15 | \description{ 16 | A complement to \code{n_miss} 17 | } 18 | \examples{ 19 | 20 | n_complete(airquality) 21 | n_complete(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/n_miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{n_miss} 4 | \alias{n_miss} 5 | \title{Return the number of missing values} 6 | \usage{ 7 | n_miss(x) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | } 12 | \value{ 13 | numeric the number of missing values 14 | } 15 | \description{ 16 | Substitute for \code{sum(is.na(data))} 17 | } 18 | \examples{ 19 | 20 | n_miss(airquality) 21 | n_miss(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/nabular.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nabular.R 3 | \name{nabular} 4 | \alias{nabular} 5 | \title{Convert data into nabular form by binding shade to it} 6 | \usage{ 7 | nabular(data, only_miss = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{data}{a dataframe} 11 | 12 | \item{only_miss}{logical - if FALSE (default) it will bind a dataframe with 13 | all of the variables duplicated with their shadow. Setting this to TRUE 14 | will bind variables only those variables that contain missing values. 15 | See the examples for more details.} 16 | 17 | \item{...}{extra options to pass to \code{\link[=recode_shadow]{recode_shadow()}} - a work in progress.} 18 | } 19 | \value{ 20 | data with the added variable shifted and the suffix \verb{_NA} 21 | } 22 | \description{ 23 | Binding a shadow matrix to a regular dataframe converts it into nabular data, 24 | which makes it easier to visualise and work with missing data. 25 | } 26 | \examples{ 27 | 28 | aq_nab <- nabular(airquality) 29 | aq_s <- bind_shadow(airquality) 30 | 31 | all.equal(aq_nab, aq_s) 32 | 33 | } 34 | \seealso{ 35 | \code{\link[=bind_shadow]{bind_shadow()}} 36 | } 37 | -------------------------------------------------------------------------------- /man/naniar-ggproto.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom-miss-point.R, R/naniar-ggproto.R, 3 | % R/stat-miss-point.R 4 | \docType{data} 5 | \name{GeomMissPoint} 6 | \alias{GeomMissPoint} 7 | \alias{naniar-ggproto} 8 | \alias{StatMissPoint} 9 | \title{naniar-ggproto} 10 | \format{ 11 | An object of class \code{StatMissPoint} (inherits from \code{Stat}, \code{ggproto}, \code{gg}) of length 6. 12 | } 13 | \usage{ 14 | StatMissPoint 15 | } 16 | \description{ 17 | These are the stat and geom overrides using ggproto from ggplot2 18 | that make naniar work. 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/naniar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/naniar-package.R 3 | \docType{package} 4 | \name{naniar} 5 | \alias{naniar-package} 6 | \alias{naniar} 7 | \title{naniar: Data Structures, Summaries, and Visualisations for Missing Data} 8 | \description{ 9 | naniar is a package to make it easier to summarise and handle missing values 10 | in R. It strives to do this in a way that is as consistent with tidyverse 11 | principles as possible. The work is fully discussed at Tierney & Cook (2023) 12 | \url{doi:10.18637/jss.v105.i07}. 13 | } 14 | \seealso{ 15 | Useful links: 16 | \itemize{ 17 | \item \url{https://github.com/njtierney/naniar} 18 | \item \url{https://naniar.njtierney.com/} 19 | \item Report bugs at \url{https://github.com/njtierney/naniar/issues} 20 | } 21 | 22 | } 23 | \author{ 24 | \strong{Maintainer}: Nicholas Tierney \email{nicholas.tierney@gmail.com} (\href{https://orcid.org/0000-0003-1460-8722}{ORCID}) 25 | 26 | Authors: 27 | \itemize{ 28 | \item Di Cook \email{dicook@monash.edu} (\href{https://orcid.org/0000-0002-3813-7155}{ORCID}) 29 | \item Miles McBain \email{miles.mcbain@gmail.com} (\href{https://orcid.org/0000-0003-2865-2548}{ORCID}) 30 | \item Colin Fay \email{contact@colinfay.me} (\href{https://orcid.org/0000-0001-7343-1846}{ORCID}) 31 | } 32 | 33 | Other contributors: 34 | \itemize{ 35 | \item Mitchell O'Hara-Wild [contributor] 36 | \item Jim Hester \email{james.f.hester@gmail.com} [contributor] 37 | \item Luke Smith [contributor] 38 | \item Andrew Heiss \email{andrew@andrewheiss.com} (\href{https://orcid.org/0000-0002-3948-3914}{ORCID}) [contributor] 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/pct-miss-complete-case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prop-pct-var-case-miss-complete.R 3 | \name{pct-miss-complete-case} 4 | \alias{pct-miss-complete-case} 5 | \alias{pct_miss_case} 6 | \alias{pct_complete_case} 7 | \title{Percentage of cases that contain a missing or complete values.} 8 | \usage{ 9 | pct_miss_case(data) 10 | 11 | pct_complete_case(data) 12 | } 13 | \arguments{ 14 | \item{data}{a dataframe} 15 | } 16 | \value{ 17 | numeric the percentage of cases that contain a missing or complete 18 | value 19 | } 20 | \description{ 21 | Calculate the percentage of cases (rows) that contain a missing or complete 22 | value. 23 | } 24 | \examples{ 25 | 26 | pct_miss_case(airquality) 27 | pct_complete_case(airquality) 28 | 29 | } 30 | \seealso{ 31 | \code{\link[=pct_miss_case]{pct_miss_case()}} \code{\link[=prop_miss_case]{prop_miss_case()}} \code{\link[=pct_miss_var]{pct_miss_var()}} \code{\link[=prop_miss_var]{prop_miss_var()}} \code{\link[=pct_complete_case]{pct_complete_case()}} \code{\link[=prop_complete_case]{prop_complete_case()}} \code{\link[=pct_complete_var]{pct_complete_var()}} \code{\link[=prop_complete_var]{prop_complete_var()}} \code{\link[=miss_prop_summary]{miss_prop_summary()}} \code{\link[=miss_case_summary]{miss_case_summary()}} \code{\link[=miss_case_table]{miss_case_table()}} \code{\link[=miss_summary]{miss_summary()}} \code{\link[=miss_var_prop]{miss_var_prop()}} \code{\link[=miss_var_run]{miss_var_run()}} \code{\link[=miss_var_span]{miss_var_span()}} \code{\link[=miss_var_summary]{miss_var_summary()}} \code{\link[=miss_var_table]{miss_var_table()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/pct-miss-complete-var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prop-pct-var-case-miss-complete.R 3 | \name{pct-miss-complete-var} 4 | \alias{pct-miss-complete-var} 5 | \alias{pct_miss_var} 6 | \alias{pct_complete_var} 7 | \title{Percentage of variables containing missings or complete values} 8 | \usage{ 9 | pct_miss_var(data) 10 | 11 | pct_complete_var(data) 12 | } 13 | \arguments{ 14 | \item{data}{a dataframe} 15 | } 16 | \value{ 17 | numeric the percent of variables that contain missing or complete 18 | data 19 | } 20 | \description{ 21 | Calculate the percentage of variables that contain a single missing or 22 | complete value. 23 | } 24 | \examples{ 25 | 26 | prop_miss_var(airquality) 27 | prop_complete_var(airquality) 28 | 29 | } 30 | \seealso{ 31 | \code{\link[=pct_miss_case]{pct_miss_case()}} \code{\link[=prop_miss_case]{prop_miss_case()}} \code{\link[=pct_miss_var]{pct_miss_var()}} \code{\link[=prop_miss_var]{prop_miss_var()}} \code{\link[=pct_complete_case]{pct_complete_case()}} \code{\link[=prop_complete_case]{prop_complete_case()}} \code{\link[=pct_complete_var]{pct_complete_var()}} \code{\link[=prop_complete_var]{prop_complete_var()}} \code{\link[=miss_prop_summary]{miss_prop_summary()}} \code{\link[=miss_case_summary]{miss_case_summary()}} \code{\link[=miss_case_table]{miss_case_table()}} \code{\link[=miss_summary]{miss_summary()}} \code{\link[=miss_var_prop]{miss_var_prop()}} \code{\link[=miss_var_run]{miss_var_run()}} \code{\link[=miss_var_span]{miss_var_span()}} \code{\link[=miss_var_summary]{miss_var_summary()}} \code{\link[=miss_var_table]{miss_var_table()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/pct_complete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{pct_complete} 4 | \alias{pct_complete} 5 | \title{Return the percent of complete values} 6 | \usage{ 7 | pct_complete(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector or data.frame} 11 | } 12 | \value{ 13 | numeric percent of complete values 14 | } 15 | \description{ 16 | The complement to \code{pct_miss} 17 | } 18 | \examples{ 19 | 20 | pct_complete(airquality) 21 | pct_complete(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/pct_miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{pct_miss} 4 | \alias{pct_miss} 5 | \title{Return the percent of missing values} 6 | \usage{ 7 | pct_miss(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector or data.frame} 11 | } 12 | \value{ 13 | numeric the percent of missing values in x 14 | } 15 | \description{ 16 | This is shorthand for \code{mean(is.na(x)) * 100} 17 | } 18 | \examples{ 19 | 20 | pct_miss(airquality) 21 | pct_miss(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/plotly_helpers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geom2plotly.R 3 | \name{plotly_helpers} 4 | \alias{plotly_helpers} 5 | \alias{to_basic.GeomMissPoint} 6 | \title{Plotly helpers (Convert a geom to a "basic" geom.)} 7 | \usage{ 8 | to_basic.GeomMissPoint(data, prestats_data, layout, params, p, ...) 9 | } 10 | \arguments{ 11 | \item{data}{the data returned by \code{ggplot2::ggplot_build()}.} 12 | 13 | \item{prestats_data}{the data before statistics are computed.} 14 | 15 | \item{layout}{the panel layout.} 16 | 17 | \item{params}{parameters for the geom, statistic, and 'constant' aesthetics} 18 | 19 | \item{p}{a ggplot2 object (the conversion may depend on scales, for 20 | instance).} 21 | 22 | \item{...}{currently ignored} 23 | } 24 | \description{ 25 | Helper functions to make it easier to automatically create 26 | plotly charts. This function makes it possible to convert ggplot2 geoms 27 | that are not included with ggplot2 itself. Users shouldn't need to use this 28 | function. It exists purely to allow other package authors to write their 29 | own conversion method(s). 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/prop-miss-complete-case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prop-pct-var-case-miss-complete.R 3 | \name{prop-miss-complete-case} 4 | \alias{prop-miss-complete-case} 5 | \alias{prop_miss_case} 6 | \alias{prop_complete_case} 7 | \title{Proportion of cases that contain a missing or complete values.} 8 | \usage{ 9 | prop_miss_case(data) 10 | 11 | prop_complete_case(data) 12 | } 13 | \arguments{ 14 | \item{data}{a dataframe} 15 | } 16 | \value{ 17 | numeric the proportion of cases that contain a missing or complete 18 | value 19 | } 20 | \description{ 21 | Calculate the proportion of cases (rows) that contain missing or complete 22 | values. 23 | } 24 | \examples{ 25 | 26 | prop_miss_case(airquality) 27 | prop_complete_case(airquality) 28 | 29 | } 30 | \seealso{ 31 | \code{\link[=pct_miss_case]{pct_miss_case()}} \code{\link[=prop_miss_case]{prop_miss_case()}} \code{\link[=pct_miss_var]{pct_miss_var()}} \code{\link[=prop_miss_var]{prop_miss_var()}} \code{\link[=pct_complete_case]{pct_complete_case()}} \code{\link[=prop_complete_case]{prop_complete_case()}} \code{\link[=pct_complete_var]{pct_complete_var()}} \code{\link[=prop_complete_var]{prop_complete_var()}} \code{\link[=miss_prop_summary]{miss_prop_summary()}} \code{\link[=miss_case_summary]{miss_case_summary()}} \code{\link[=miss_case_table]{miss_case_table()}} \code{\link[=miss_summary]{miss_summary()}} \code{\link[=miss_var_prop]{miss_var_prop()}} \code{\link[=miss_var_run]{miss_var_run()}} \code{\link[=miss_var_span]{miss_var_span()}} \code{\link[=miss_var_summary]{miss_var_summary()}} \code{\link[=miss_var_table]{miss_var_table()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/prop-miss-complete-var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prop-pct-var-case-miss-complete.R 3 | \name{prop-miss-complete-var} 4 | \alias{prop-miss-complete-var} 5 | \alias{prop_miss_var} 6 | \alias{prop_complete_var} 7 | \title{Proportion of variables containing missings or complete values} 8 | \usage{ 9 | prop_miss_var(data) 10 | 11 | prop_complete_var(data) 12 | } 13 | \arguments{ 14 | \item{data}{a dataframe} 15 | } 16 | \value{ 17 | numeric the proportion of variables that contain missing or complete 18 | data 19 | } 20 | \description{ 21 | Calculate the proportion of variables that contain a single missing or 22 | complete values. 23 | } 24 | \examples{ 25 | 26 | prop_miss_var(airquality) 27 | prop_complete_var(airquality) 28 | 29 | } 30 | \seealso{ 31 | \code{\link[=pct_miss_case]{pct_miss_case()}} \code{\link[=prop_miss_case]{prop_miss_case()}} \code{\link[=pct_miss_var]{pct_miss_var()}} \code{\link[=prop_miss_var]{prop_miss_var()}} \code{\link[=pct_complete_case]{pct_complete_case()}} \code{\link[=prop_complete_case]{prop_complete_case()}} \code{\link[=pct_complete_var]{pct_complete_var()}} \code{\link[=prop_complete_var]{prop_complete_var()}} \code{\link[=miss_prop_summary]{miss_prop_summary()}} \code{\link[=miss_case_summary]{miss_case_summary()}} \code{\link[=miss_case_table]{miss_case_table()}} \code{\link[=miss_summary]{miss_summary()}} \code{\link[=miss_var_prop]{miss_var_prop()}} \code{\link[=miss_var_run]{miss_var_run()}} \code{\link[=miss_var_span]{miss_var_span()}} \code{\link[=miss_var_summary]{miss_var_summary()}} \code{\link[=miss_var_table]{miss_var_table()}} 32 | } 33 | -------------------------------------------------------------------------------- /man/prop_complete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{prop_complete} 4 | \alias{prop_complete} 5 | \title{Return the proportion of complete values} 6 | \usage{ 7 | prop_complete(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector or data.frame} 11 | } 12 | \value{ 13 | numeric proportion of complete values 14 | } 15 | \description{ 16 | The complement to \code{prop_miss} 17 | } 18 | \examples{ 19 | 20 | prop_complete(airquality) 21 | prop_complete(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/prop_miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n-prop-miss-complete.R 3 | \name{prop_miss} 4 | \alias{prop_miss} 5 | \title{Return the proportion of missing values} 6 | \usage{ 7 | prop_miss(x) 8 | } 9 | \arguments{ 10 | \item{x}{vector or data.frame} 11 | } 12 | \value{ 13 | numeric the proportion of missing values in x 14 | } 15 | \description{ 16 | This is shorthand for \code{mean(is.na(x))} 17 | } 18 | \examples{ 19 | 20 | prop_miss(airquality) 21 | prop_miss(airquality$Ozone) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/recode_shadow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadow-recode.R 3 | \name{recode_shadow} 4 | \alias{recode_shadow} 5 | \alias{recode_shadow.data.frame} 6 | \alias{recode_shadow.grouped_df} 7 | \title{Add special missing values to the shadow matrix} 8 | \usage{ 9 | recode_shadow(data, ...) 10 | 11 | \method{recode_shadow}{data.frame}(data, ...) 12 | 13 | \method{recode_shadow}{grouped_df}(data, ...) 14 | } 15 | \arguments{ 16 | \item{data}{data.frame} 17 | 18 | \item{...}{A sequence of two-sided formulas as in dplyr::case_when, 19 | but when a wrapper function \code{.where} written around it.} 20 | } 21 | \value{ 22 | a dataframe with altered shadows 23 | } 24 | \description{ 25 | It can be useful to add special missing values, naniar supports this with 26 | the \code{recode_shadow} function. 27 | } 28 | \examples{ 29 | 30 | df <- tibble::tribble( 31 | ~wind, ~temp, 32 | -99, 45, 33 | 68, NA, 34 | 72, 25 35 | ) 36 | 37 | dfs <- bind_shadow(df) 38 | 39 | dfs 40 | 41 | recode_shadow(dfs, temp = .where(wind == -99 ~ "bananas")) 42 | 43 | recode_shadow(dfs, 44 | temp = .where(wind == -99 ~ "bananas")) \%>\% 45 | recode_shadow(wind = .where(wind == -99 ~ "apples")) 46 | 47 | } 48 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{\%>\%} 7 | \alias{is_na} 8 | \alias{are_na} 9 | \alias{vis_miss} 10 | \title{Objects exported from other packages} 11 | \keyword{internal} 12 | \description{ 13 | These objects are imported from other packages. Follow the links 14 | below to see their documentation. 15 | 16 | \describe{ 17 | \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}} 18 | 19 | \item{rlang}{\code{\link[rlang]{are_na}}, \code{\link[rlang:are_na]{is_na}}} 20 | 21 | \item{visdat}{\code{\link[visdat]{vis_miss}}} 22 | }} 23 | 24 | -------------------------------------------------------------------------------- /man/replace_na_with.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/replace_na_with.R 3 | \name{replace_na_with} 4 | \alias{replace_na_with} 5 | \title{Replace NA value with provided value} 6 | \usage{ 7 | replace_na_with(x, value) 8 | } 9 | \arguments{ 10 | \item{x}{vector} 11 | 12 | \item{value}{value to replace} 13 | } 14 | \value{ 15 | vector with replaced values 16 | } 17 | \description{ 18 | This function helps you replace NA values with a single provided value. 19 | This can be classed as a kind of imputation, and is powered by 20 | \code{\link[=impute_fixed]{impute_fixed()}}. However, we would generally recommend to impute using 21 | other model based approaches. See the \code{simputation} package, for example 22 | \code{\link[simputation:impute_lm]{simputation::impute_lm()}}. See \code{\link[tidyr:replace_na]{tidyr::replace_na()}} for a slightly 23 | different approach, \code{\link[dplyr:coalesce]{dplyr::coalesce()}} for replacing NAs with values from 24 | other vectors, and \code{\link[dplyr:na_if]{dplyr::na_if()}} to replace specified values with NA. 25 | } 26 | \examples{ 27 | 28 | library(naniar) 29 | x <- c(1:5, NA, NA, NA) 30 | x 31 | replace_na_with(x, 0L) 32 | replace_na_with(x, "unknown") 33 | 34 | library(dplyr) 35 | dat <- tibble( 36 | ones = c(NA,1,1), 37 | twos = c(NA,NA, 2), 38 | threes = c(NA, NA, NA) 39 | ) 40 | 41 | dat 42 | 43 | dat \%>\% 44 | mutate( 45 | ones = replace_na_with(ones, 0), 46 | twos = replace_na_with(twos, -99), 47 | threes = replace_na_with(threes, "unknowns") 48 | ) 49 | 50 | dat \%>\% 51 | mutate( 52 | across( 53 | everything(), 54 | \(x) replace_na_with(x, -99) 55 | ) 56 | ) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /man/replace_to_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/replace-to-na.R 3 | \name{replace_to_na} 4 | \alias{replace_to_na} 5 | \title{Replace values with missings} 6 | \usage{ 7 | replace_to_na(...) 8 | } 9 | \arguments{ 10 | \item{...}{additional arguments for methods.} 11 | } 12 | \value{ 13 | values replaced by NA 14 | } 15 | \description{ 16 | This function is Defunct, please see \code{\link[=replace_with_na]{replace_with_na()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/replace_with_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/replace-with-na.R 3 | \name{replace_with_na} 4 | \alias{replace_with_na} 5 | \title{Replace values with missings} 6 | \usage{ 7 | replace_with_na(data, replace = list(), ...) 8 | } 9 | \arguments{ 10 | \item{data}{A data.frame} 11 | 12 | \item{replace}{A named list given the NA to replace values for each column} 13 | 14 | \item{...}{additional arguments for methods. Currently unused} 15 | } 16 | \value{ 17 | Dataframe with values replaced by NA. 18 | } 19 | \description{ 20 | Specify variables and their values that you want to convert to missing values. 21 | This is a complement to \code{tidyr::replace_na}. 22 | } 23 | \examples{ 24 | 25 | dat_ms <- tibble::tribble(~x, ~y, ~z, 26 | 1, "A", -100, 27 | 3, "N/A", -99, 28 | NA, NA, -98, 29 | -99, "E", -101, 30 | -98, "F", -1) 31 | 32 | replace_with_na(dat_ms, 33 | replace = list(x = -99)) 34 | 35 | replace_with_na(dat_ms, 36 | replace = list(x = c(-99, -98))) 37 | 38 | replace_with_na(dat_ms, 39 | replace = list(x = c(-99, -98), 40 | y = c("N/A"), 41 | z = c(-101))) 42 | } 43 | \seealso{ 44 | \code{\link[=replace_with_na]{replace_with_na()}} \code{\link[=replace_with_na_all]{replace_with_na_all()}} \code{\link[=replace_with_na_at]{replace_with_na_at()}} \code{\link[=replace_with_na_if]{replace_with_na_if()}} 45 | } 46 | -------------------------------------------------------------------------------- /man/replace_with_na_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scoped-replace-with-na.R 3 | \name{replace_with_na_all} 4 | \alias{replace_with_na_all} 5 | \title{Replace all values with NA where a certain condition is met} 6 | \usage{ 7 | replace_with_na_all(data, condition) 8 | } 9 | \arguments{ 10 | \item{data}{A dataframe} 11 | 12 | \item{condition}{A condition required to be TRUE to set NA. Here, the condition 13 | is specified with a formula, following the syntax: \verb{~.x \{condition\}}. 14 | For example, writing \code{~.x < 20} would mean "where a variable value is less 15 | than 20, replace with NA".} 16 | } 17 | \description{ 18 | This function takes a dataframe and replaces all values that meet the 19 | condition specified as an NA value, following a special syntax. 20 | } 21 | \examples{ 22 | dat_ms <- tibble::tribble(~x, ~y, ~z, 23 | 1, "A", -100, 24 | 3, "N/A", -99, 25 | NA, NA, -98, 26 | -99, "E", -101, 27 | -98, "F", -1) 28 | 29 | dat_ms 30 | #replace all instances of -99 with NA 31 | replace_with_na_all(data = dat_ms, 32 | condition = ~.x == -99) 33 | 34 | # replace all instances of -99 or -98, or "N/A" with NA 35 | replace_with_na_all(dat_ms, 36 | condition = ~.x \%in\% c(-99, -98, "N/A")) 37 | # replace all instances of common na strings 38 | replace_with_na_all(dat_ms, 39 | condition = ~.x \%in\% common_na_strings) 40 | 41 | # where works with functions 42 | replace_with_na_all(airquality, ~ sqrt(.x) < 5) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/replace_with_na_at.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scoped-replace-with-na.R 3 | \name{replace_with_na_at} 4 | \alias{replace_with_na_at} 5 | \title{Replace specified variables with NA where a certain condition is met} 6 | \usage{ 7 | replace_with_na_at(data, .vars, condition) 8 | } 9 | \arguments{ 10 | \item{data}{dataframe} 11 | 12 | \item{.vars}{A character string of variables to replace with NA values} 13 | 14 | \item{condition}{A condition required to be TRUE to set NA. Here, the condition 15 | is specified with a formula, following the syntax: \verb{~.x \{condition\}}. 16 | For example, writing \code{~.x < 20} would mean "where a variable value is less 17 | than 20, replace with NA".} 18 | } 19 | \value{ 20 | a dataframe 21 | } 22 | \description{ 23 | Replace specified variables with NA where a certain condition is met 24 | } 25 | \examples{ 26 | 27 | dat_ms <- tibble::tribble(~x, ~y, ~z, 28 | 1, "A", -100, 29 | 3, "N/A", -99, 30 | NA, NA, -98, 31 | -99, "E", -101, 32 | -98, "F", -1) 33 | 34 | dat_ms 35 | 36 | replace_with_na_at(data = dat_ms, 37 | .vars = "x", 38 | condition = ~.x == -99) 39 | 40 | replace_with_na_at(data = dat_ms, 41 | .vars = c("x","z"), 42 | condition = ~.x == -99) 43 | 44 | # replace using values in common_na_strings 45 | replace_with_na_at(data = dat_ms, 46 | .vars = c("x","z"), 47 | condition = ~.x \%in\% common_na_strings) 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/replace_with_na_if.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scoped-replace-with-na.R 3 | \name{replace_with_na_if} 4 | \alias{replace_with_na_if} 5 | \title{Replace values with NA based on some condition, for variables that meet some predicate} 6 | \usage{ 7 | replace_with_na_if(data, .predicate, condition) 8 | } 9 | \arguments{ 10 | \item{data}{Dataframe} 11 | 12 | \item{.predicate}{A predicate function to be applied to the columns or a 13 | logical vector.} 14 | 15 | \item{condition}{A condition required to be TRUE to set NA. Here, the condition 16 | is specified with a formula, following the syntax: \verb{~.x \{condition\}}. 17 | For example, writing \code{~.x < 20} would mean "where a variable value is less 18 | than 20, replace with NA".} 19 | } 20 | \value{ 21 | Dataframe 22 | } 23 | \description{ 24 | Replace values with NA based on some condition, for variables that meet some predicate 25 | } 26 | \examples{ 27 | 28 | dat_ms <- tibble::tribble(~x, ~y, ~z, 29 | 1, "A", -100, 30 | 3, "N/A", -99, 31 | NA, NA, -98, 32 | -99, "E", -101, 33 | -98, "F", -1) 34 | 35 | dat_ms 36 | 37 | replace_with_na_if(data = dat_ms, 38 | .predicate = is.character, 39 | condition = ~.x == "N/A") 40 | replace_with_na_if(data = dat_ms, 41 | .predicate = is.character, 42 | condition = ~.x \%in\% common_na_strings) 43 | 44 | replace_with_na(dat_ms, 45 | to_na = list(x = c(-99, -98), 46 | y = c("N/A"), 47 | z = c(-101))) 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/set-prop-n-miss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/set-n-prop-miss.R 3 | \name{set-prop-n-miss} 4 | \alias{set-prop-n-miss} 5 | \alias{set_prop_miss} 6 | \alias{set_n_miss} 7 | \title{Set a proportion or number of missing values} 8 | \usage{ 9 | set_prop_miss(x, prop = 0.1) 10 | 11 | set_n_miss(x, n = 1) 12 | } 13 | \arguments{ 14 | \item{x}{vector of values to set missing} 15 | 16 | \item{prop}{proportion of values between 0 and 1 to set as missing} 17 | 18 | \item{n}{number of values to set missing} 19 | } 20 | \value{ 21 | vector with missing values added 22 | } 23 | \description{ 24 | Set a proportion or number of missing values 25 | } 26 | \examples{ 27 | vec <- rnorm(5) 28 | set_prop_miss(vec, 0.2) 29 | set_prop_miss(vec, 0.4) 30 | set_n_miss(vec, 1) 31 | set_n_miss(vec, 4) 32 | } 33 | -------------------------------------------------------------------------------- /man/shade.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shade.R 3 | \name{shade} 4 | \alias{shade} 5 | \title{Create new levels of missing} 6 | \usage{ 7 | shade(x, ..., extra_levels = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | 12 | \item{...}{additional levels of missing to add} 13 | 14 | \item{extra_levels}{extra levels you might to specify for the factor.} 15 | } 16 | \description{ 17 | Returns (at least) factors of !NA and NA, where !NA indicates a datum that is 18 | not missing, and NA indicates missingness. It also allows you to specify 19 | some new missings, if you like. This function is what powers the factor 20 | levels in \code{as_shadow()}. 21 | } 22 | \examples{ 23 | df <- tibble::tribble( 24 | ~wind, ~temp, 25 | -99, 45, 26 | 68, NA, 27 | 72, 25 28 | ) 29 | 30 | shade(df$wind) 31 | 32 | shade(df$wind, inst_fail = -99) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/shadow_long.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{shadow_long} 4 | \alias{shadow_long} 5 | \title{Reshape shadow data into a long format} 6 | \usage{ 7 | shadow_long(shadow_data, ..., fn_value_transform = NULL, only_main_vars = TRUE) 8 | } 9 | \arguments{ 10 | \item{shadow_data}{a data.frame} 11 | 12 | \item{...}{bare name of variables that you want to focus on} 13 | 14 | \item{fn_value_transform}{function to transform the "value" column. Default 15 | is NULL, which defaults to \code{as.character}. Be aware that \code{as.numeric} may 16 | fail for some instances if it cannot coerce the value into numeric. See 17 | the examples.} 18 | 19 | \item{only_main_vars}{logical - do you want to filter down to main variables?} 20 | } 21 | \value{ 22 | data in long format, with columns \code{variable}, \code{value}, \code{variable_NA}, and \code{value_NA}. 23 | } 24 | \description{ 25 | Once data is in \code{nabular} form, where the shadow is bound to the data, it 26 | can be useful to reshape it into a long format with the shadow columns 27 | in a separate grouping - so you have \code{variable}, \code{value}, and 28 | \code{variable_NA} and \code{value_NA}. 29 | } 30 | \examples{ 31 | 32 | aq_shadow <- nabular(airquality) 33 | 34 | shadow_long(aq_shadow) 35 | 36 | # then filter only on Ozone 37 | shadow_long(aq_shadow, Ozone) 38 | 39 | shadow_long(aq_shadow, Ozone, Solar.R) 40 | 41 | # ensure `value` is numeric 42 | shadow_long(aq_shadow, fn_value_transform = as.numeric) 43 | shadow_long(aq_shadow, Ozone, Solar.R, fn_value_transform = as.numeric) 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/shadow_shift.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadow-shifters.R 3 | \name{shadow_shift} 4 | \alias{shadow_shift} 5 | \title{Shift missing values to facilitate missing data exploration/visualisation} 6 | \usage{ 7 | shadow_shift(...) 8 | } 9 | \arguments{ 10 | \item{...}{arguments to \code{\link[=impute_below]{impute_below()}}.} 11 | } 12 | \description{ 13 | \code{shadow_shift} transforms missing values to facilitate visualisation, and has 14 | different behaviour for different types of variables. For numeric 15 | variables, the values are shifted to 10\% below the minimum value for a given 16 | variable plus some jittered noise, to separate repeated values, so that 17 | missing values can be visualised along with the rest of the data. 18 | } 19 | \details{ 20 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 21 | } 22 | \examples{ 23 | airquality$Ozone 24 | shadow_shift(airquality$Ozone) 25 | \dontrun{ 26 | library(dplyr) 27 | airquality \%>\% 28 | mutate(Ozone_shift = shadow_shift(Ozone)) 29 | } 30 | } 31 | \seealso{ 32 | \code{\link[=add_shadow_shift]{add_shadow_shift()}} \code{\link[=cast_shadow_shift]{cast_shadow_shift()}} \code{\link[=cast_shadow_shift_label]{cast_shadow_shift_label()}} 33 | } 34 | -------------------------------------------------------------------------------- /man/unbinders.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadows.R 3 | \name{unbinders} 4 | \alias{unbinders} 5 | \alias{unbind_shadow} 6 | \alias{unbind_data} 7 | \title{Unbind (remove) shadow from data, and vice versa} 8 | \usage{ 9 | unbind_shadow(data) 10 | 11 | unbind_data(data) 12 | } 13 | \arguments{ 14 | \item{data}{data.frame containing shadow columns (created by \code{\link[=bind_shadow]{bind_shadow()}})} 15 | } 16 | \value{ 17 | \code{data.frame} without shadow columns if using \code{\link[=unbind_shadow]{unbind_shadow()}}, or 18 | without the original data, if using \code{\link[=unbind_data]{unbind_data()}}. 19 | } 20 | \description{ 21 | Remove the shadow variables (which end in \verb{_NA}) from the data, or vice versa. 22 | This will also remove the \code{nabular} class from the data. 23 | } 24 | \examples{ 25 | 26 | # bind shadow columns 27 | aq_sh <- bind_shadow(airquality) 28 | 29 | # print data 30 | aq_sh 31 | 32 | # remove shadow columns 33 | unbind_shadow(aq_sh) 34 | 35 | # remove data 36 | unbind_data(aq_sh) 37 | 38 | # errors when you don't use data with shadows 39 | \dontrun{ 40 | unbind_data(airquality) 41 | unbind_shadow(airquality) 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/where.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shadow-recode.R 3 | \name{where} 4 | \alias{where} 5 | \alias{.where} 6 | \title{Split a call into two components with a useful verb name} 7 | \usage{ 8 | .where(...) 9 | } 10 | \arguments{ 11 | \item{...}{case_when style formula} 12 | } 13 | \value{ 14 | a list of "condition" and "suffix" arguments 15 | } 16 | \description{ 17 | This function is used inside \code{recode_shadow} to help evaluate the formula 18 | call effectively. \code{.where} is a special function designed for use in 19 | \code{recode_shadow}, and you shouldn't use it outside of it 20 | } 21 | \examples{ 22 | 23 | \dontrun{ 24 | df <- tibble::tribble( 25 | ~wind, ~temp, 26 | -99, 45, 27 | 68, NA, 28 | 72, 25 29 | ) 30 | 31 | dfs <- bind_shadow(df) 32 | 33 | recode_shadow(dfs, 34 | temp = .where(wind == -99 ~ "bananas")) 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/where_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/where-na.R 3 | \name{where_na} 4 | \alias{where_na} 5 | \title{Which rows and cols contain missings?} 6 | \usage{ 7 | where_na(x) 8 | } 9 | \arguments{ 10 | \item{x}{a dataframe} 11 | } 12 | \value{ 13 | a matrix with columns "row" and "col", which refer to the row and 14 | column that identify the position of a missing value in a dataframe 15 | } 16 | \description{ 17 | Internal function that is short for \code{which(is.na(x), arr.ind = TRUE)}. 18 | Creates array index locations of missing values in a dataframe. 19 | } 20 | \examples{ 21 | 22 | where_na(airquality) 23 | where_na(oceanbuoys$sea_temp_c) 24 | 25 | } 26 | \seealso{ 27 | \code{\link[=which_na]{which_na()}} 28 | } 29 | -------------------------------------------------------------------------------- /man/which_are_shade.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shade.R 3 | \name{which_are_shade} 4 | \alias{which_are_shade} 5 | \title{Which variables are shades?} 6 | \usage{ 7 | which_are_shade(.tbl) 8 | } 9 | \arguments{ 10 | \item{.tbl}{a data.frame or tbl} 11 | } 12 | \value{ 13 | numeric - which column numbers contain shade information 14 | } 15 | \description{ 16 | This function tells us which variables contain shade information 17 | } 18 | \examples{ 19 | 20 | df_shadow <- bind_shadow(airquality) 21 | 22 | which_are_shade(df_shadow) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/which_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/where-na.R 3 | \name{which_na} 4 | \alias{which_na} 5 | \title{Which elements contain missings?} 6 | \usage{ 7 | which_na(x) 8 | } 9 | \arguments{ 10 | \item{x}{a dataframe} 11 | } 12 | \value{ 13 | integer locations of missing values. 14 | } 15 | \description{ 16 | Equivalent to \code{which(is.na())} - returns integer locations of missing values. 17 | } 18 | \examples{ 19 | 20 | which_na(airquality) 21 | 22 | } 23 | \seealso{ 24 | \code{\link[=where_na]{where_na()}} 25 | } 26 | -------------------------------------------------------------------------------- /missingness-data-structures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/missingness-data-structures.png -------------------------------------------------------------------------------- /naniar.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: a389c67c-7dea-45d4-9bbd-9a24b84fd28a 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: No 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: knitr 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | data.sqlite 6 | *.html 7 | download 8 | lib 9 | cloud.noindex 10 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:-----------------------------------| 5 | |version |R version 4.3.3 (2024-02-29) | 6 | |os |macOS Sonoma 14.3.1 | 7 | |system |aarch64, darwin20 | 8 | |ui |RStudio | 9 | |language |(EN) | 10 | |collate |en_US.UTF-8 | 11 | |ctype |en_US.UTF-8 | 12 | |tz |Australia/Melbourne | 13 | |date |2024-03-04 | 14 | |rstudio |2023.12.1+402 Ocean Storm (desktop) | 15 | |pandoc |NA | 16 | 17 | # Dependencies 18 | 19 | |package |old |new |Δ | 20 | |:-------|:-----|:-----|:--| 21 | |naniar |1.0.0 |1.1.0 |* | 22 | |ggplot2 |NA |3.5.0 |* | 23 | |viridis |NA |0.6.5 |* | 24 | 25 | # Revdeps 26 | 27 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 6 reverse dependencies (5 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /tests/figs/deps.txt: -------------------------------------------------------------------------------- 1 | - vdiffr-svg-engine: 1.0 2 | - vdiffr: 0.3.2.2 3 | - freetypeharfbuzz: 0.2.5 4 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test( 3 | vignettes = TRUE, 4 | error = FALSE, 5 | skip_on_cran = TRUE 6 | ) 7 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/tests.html 7 | # * https://testthat.r-lib.org/reference/test_package.html#special-files 8 | 9 | library(testthat) 10 | library(naniar) 11 | 12 | test_check("naniar") 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/add-label-shadow.md: -------------------------------------------------------------------------------- 1 | # add_label_shadow errors when using a dataframe with no shadow 2 | 3 | Code 4 | add_label_shadow(dat) 5 | Condition 6 | Error in `add_label_shadow()`: 7 | ! add_label_shadow works with shadow data, which has columns 8 | created by `shade()`, `as_shadow()`, or `bind_shadow()` 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/add-shadow.md: -------------------------------------------------------------------------------- 1 | # add_shadow returns a nice error message when no variables are provided 2 | 3 | Code 4 | add_shadow(dat) 5 | Condition 6 | Error in `add_shadow()`: 7 | ! argument must be specified 8 | {.fun add_shadow} requires variables to be selected 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as-shadow.md: -------------------------------------------------------------------------------- 1 | # as_shadow errors when given non dataframe or 0 entry 2 | 3 | Code 4 | as_shadow(0) 5 | Condition 6 | Error in `as_shadow()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | as_shadow("a") 14 | Condition 15 | Error in `as_shadow()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | as_shadow(matrix(airquality)) 23 | Condition 24 | Error in `as_shadow()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | as_shadow(NULL) 32 | Condition 33 | Error in `as_shadow()`: 34 | ! Input must not be NULL 35 | Input is 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/cast-shadow-shift-label.md: -------------------------------------------------------------------------------- 1 | # cast_shadow_shift_label returns nice error if variables aren't included 2 | 3 | Code 4 | cast_shadow_shift(airquality) 5 | Condition 6 | Error in `cast_shadow()`: 7 | ! argument must be specified 8 | {.fun cast_shadow} requires variables to be selected after the data 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/cast-shadow-shift.md: -------------------------------------------------------------------------------- 1 | # cast_shadow_shift returns nice error when variables aren't included 2 | 3 | Code 4 | cast_shadow_shift(airquality) 5 | Condition 6 | Error in `cast_shadow()`: 7 | ! argument must be specified 8 | {.fun cast_shadow} requires variables to be selected after the data 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/gather-shadow.md: -------------------------------------------------------------------------------- 1 | # gather_shadow errors when given non dataframe or 0 entry 2 | 3 | Code 4 | gather_shadow(0) 5 | Condition 6 | Error in `as_shadow()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | gather_shadow(matrix(0)) 14 | Condition 15 | Error in `as_shadow()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | gather_shadow(NULL) 23 | Condition 24 | Error in `as_shadow()`: 25 | ! Input must not be NULL 26 | Input is 27 | 28 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/impute-below.md: -------------------------------------------------------------------------------- 1 | # impute_below returns an error when given the wrong kind of object 2 | 3 | Code 4 | impute_below(0+3i) 5 | Condition 6 | Error in `impute_below()`: 7 | ! `impute_below()` does not know how to deal with data of class 8 | Check if your input is more than length one, and that you are using the right function. Perhaps you meant to apply this to many variables in a data frame? See the examples dor details on doing this with `across()` 9 | 10 | # impute_below_all errors when given wrong object 11 | 12 | Code 13 | impute_below_all(as.POSIXct(111, origin = "1970-01-01")) 14 | Condition 15 | Error in `impute_below_all()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/impute-median.md: -------------------------------------------------------------------------------- 1 | # impute_median and scoped variants fail when given wrong input 2 | 3 | Code 4 | impute_median_if(numeric(0)) 5 | Condition 6 | Error in `impute_median_if()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | impute_median_at(numeric(0)) 14 | Condition 15 | Error in `impute_median_at()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | impute_median_all(numeric(0)) 23 | Condition 24 | Error in `impute_median_all()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | impute_median_if(NULL) 32 | Condition 33 | Error in `impute_median_if()`: 34 | ! Input must inherit from 35 | We see class: 36 | 37 | --- 38 | 39 | Code 40 | impute_median_at(NULL) 41 | Condition 42 | Error in `impute_median_at()`: 43 | ! Input must inherit from 44 | We see class: 45 | 46 | --- 47 | 48 | Code 49 | impute_mean_all(NULL) 50 | Condition 51 | Error in `impute_mean_all()`: 52 | ! Input must inherit from 53 | We see class: 54 | 55 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/label-miss-1d.md: -------------------------------------------------------------------------------- 1 | # label_miss_1d errors on a NULL entry 2 | 3 | Code 4 | label_miss_1d(NULL) 5 | Condition 6 | Error in `label_miss_1d()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | # label_miss_1d identifies the correct location of missingness 11 | 12 | Code 13 | label_miss_1d(test_df$x) 14 | Output 15 | [1] Missing Not Missing Not Missing 16 | Levels: Missing Not Missing 17 | 18 | --- 19 | 20 | Code 21 | label_miss_1d(test_df$y) 22 | Output 23 | [1] Not Missing Missing Not Missing 24 | Levels: Missing Not Missing 25 | 26 | --- 27 | 28 | Code 29 | label_miss_1d(test_df$z) 30 | Output 31 | [1] Not Missing Not Missing Not Missing 32 | Levels: Missing Not Missing 33 | 34 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/label-miss-2d.md: -------------------------------------------------------------------------------- 1 | # label_miss_2d errors on the first NULL entry 2 | 3 | Code 4 | label_miss_2d(NULL, 3) 5 | Condition 6 | Error in `label_miss_2d()`: 7 | ! Input cannot be NULL 8 | We see the first argument, `x1` is: 9 | We see the second argument, `x2` is: 10 | 11 | # label_miss_2d errors on the second NULL entry 12 | 13 | Code 14 | label_miss_2d(3, NULL) 15 | Condition 16 | Error in `label_miss_2d()`: 17 | ! Input cannot be NULL 18 | We see the first argument, `x1` is: 19 | We see the second argument, `x2` is: 20 | 21 | # label_miss_2d errors when both are NULL 22 | 23 | Code 24 | label_miss_2d(NULL, NULL) 25 | Condition 26 | Error in `label_miss_2d()`: 27 | ! Input cannot be NULL 28 | We see the first argument, `x1` is: 29 | We see the second argument, `x2` is: 30 | 31 | # label_miss_2d identifies the correct location of missingness 32 | 33 | Code 34 | label_miss_2d(test_df$x, test_df$y) 35 | Output 36 | [1] Missing Missing Not Missing 37 | Levels: Missing Not Missing 38 | 39 | --- 40 | 41 | Code 42 | label_miss_2d(test_df$y, test_df$z) 43 | Output 44 | [1] Not Missing Missing Not Missing 45 | Levels: Missing Not Missing 46 | 47 | --- 48 | 49 | Code 50 | label_miss_2d(test_df$x, test_df$z) 51 | Output 52 | [1] Missing Not Missing Not Missing 53 | Levels: Missing Not Missing 54 | 55 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-case-summary.md: -------------------------------------------------------------------------------- 1 | # miss_case_summary errors on NULL 2 | 3 | Code 4 | miss_case_summary(NULL) 5 | Condition 6 | Error in `miss_case_summary()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | # miss_case_summary errors when a non-dataframe given 11 | 12 | Code 13 | miss_case_summary(1) 14 | Condition 15 | Error in `miss_case_summary()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | miss_case_summary("a") 23 | Condition 24 | Error in `miss_case_summary()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | miss_case_summary(matrix(0)) 32 | Condition 33 | Error in `miss_case_summary()`: 34 | ! Input must inherit from 35 | We see class: 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-case-table.md: -------------------------------------------------------------------------------- 1 | # miss_case_table errors when given wrong type 2 | 3 | Code 4 | miss_case_table(NULL) 5 | Condition 6 | Error in `miss_case_table()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | --- 11 | 12 | Code 13 | miss_case_table(1) 14 | Condition 15 | Error in `miss_case_table()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | miss_case_table("a") 23 | Condition 24 | Error in `miss_case_table()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | miss_case_table(matrix(0)) 32 | Condition 33 | Error in `miss_case_table()`: 34 | ! Input must inherit from 35 | We see class: 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-prop-summary.md: -------------------------------------------------------------------------------- 1 | # miss_prop_summary errors when given non dataframe or 0 entry 2 | 3 | Code 4 | miss_prop_summary(0) 5 | Condition 6 | Error in `miss_prop_summary()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | miss_prop_summary("a") 14 | Condition 15 | Error in `miss_prop_summary()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | miss_prop_summary(matrix(airquality)) 23 | Condition 24 | Error in `miss_prop_summary()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | miss_prop_summary(NULL) 32 | Condition 33 | Error in `miss_prop_summary()`: 34 | ! Input must not be NULL 35 | Input is 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-scan-count.md: -------------------------------------------------------------------------------- 1 | # miss_scan_count returns an error when no search is provided 2 | 3 | Code 4 | miss_scan_count(dat_ms) 5 | Condition 6 | Error in `miss_scan_count()`: 7 | ! argument "search" is missing, with no default 8 | 9 | # miss_scan_count returns an error when no data is provided 10 | 11 | Code 12 | miss_scan_count(search = -99) 13 | Condition 14 | Error in `miss_scan_count()`: 15 | ! argument "data" is missing, with no default 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-summary.md: -------------------------------------------------------------------------------- 1 | # miss_summary errors when given non dataframe or 0 entry 2 | 3 | Code 4 | miss_summary(0) 5 | Condition 6 | Error in `miss_summary()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | miss_summary("a") 14 | Condition 15 | Error in `miss_summary()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | miss_summary(matrix(airquality)) 23 | Condition 24 | Error in `miss_summary()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | miss_summary(NULL) 32 | Condition 33 | Error in `miss_summary()`: 34 | ! Input must not be NULL 35 | Input is 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-var-case-cumsum.md: -------------------------------------------------------------------------------- 1 | # miss_var_cumsum gives warning 2 | 3 | `miss_var_cumsum()` was deprecated in naniar 1.1.0. 4 | i Please use `miss_var_summary(data, add_cumsum = TRUE)` 5 | 6 | # miss_var_cumsum gives warning with grouping 7 | 8 | `miss_var_cumsum()` was deprecated in naniar 1.1.0. 9 | i Please use `miss_var_summary(data, add_cumsum = TRUE)` 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-var-summary.md: -------------------------------------------------------------------------------- 1 | # miss_var_summary errors when a non-dataframe given 2 | 3 | Code 4 | miss_var_summary(NULL) 5 | Condition 6 | Error in `miss_var_summary()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | --- 11 | 12 | Code 13 | miss_var_summary(matrix(0)) 14 | Condition 15 | Error in `miss_var_summary()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-var-table.md: -------------------------------------------------------------------------------- 1 | # miss_var_table errors on NULL 2 | 3 | Code 4 | miss_var_table(NULL) 5 | Condition 6 | Error in `miss_var_table()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | # miss_var_table errors when a non-dataframe given 11 | 12 | Code 13 | miss_var_table(1) 14 | Condition 15 | Error in `miss_var_table()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | miss_var_table("a") 23 | Condition 24 | Error in `miss_var_table()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | miss_var_table(matrix(0)) 32 | Condition 33 | Error in `miss_var_table()`: 34 | ! Input must inherit from 35 | We see class: 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/miss-var-which.md: -------------------------------------------------------------------------------- 1 | # miss-var-which errors on NULL 2 | 3 | Code 4 | miss_var_which(NULL) 5 | Condition 6 | Error in `miss_var_which()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/nabular.md: -------------------------------------------------------------------------------- 1 | # nabular errors when given non dataframe or 0 entry 2 | 3 | Code 4 | nabular(0) 5 | Condition 6 | Error in `as_shadow()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | nabular("a") 14 | Condition 15 | Error in `as_shadow()`: 16 | ! Input must inherit from 17 | We see class: 18 | 19 | --- 20 | 21 | Code 22 | nabular(matrix(0)) 23 | Condition 24 | Error in `as_shadow()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | nabular(NULL) 32 | Condition 33 | Error in `as_shadow()`: 34 | ! Input must not be NULL 35 | Input is 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/prop_row.md: -------------------------------------------------------------------------------- 1 | # rowwise errors for non data frames 2 | 3 | Code 4 | n_miss_row(numeric(0)) 5 | Condition 6 | Error in `n_miss_row()`: 7 | ! Input must inherit from 8 | We see class: 9 | 10 | --- 11 | 12 | Code 13 | n_miss_row(NULL) 14 | Condition 15 | Error in `n_miss_row()`: 16 | ! Input must not be NULL 17 | Input is 18 | 19 | --- 20 | 21 | Code 22 | n_complete_row(numeric(0)) 23 | Condition 24 | Error in `n_complete_row()`: 25 | ! Input must inherit from 26 | We see class: 27 | 28 | --- 29 | 30 | Code 31 | n_complete_row(NULL) 32 | Condition 33 | Error in `n_complete_row()`: 34 | ! Input must not be NULL 35 | Input is 36 | 37 | --- 38 | 39 | Code 40 | prop_miss_row(numeric(0)) 41 | Condition 42 | Error in `prop_miss_row()`: 43 | ! Input must inherit from 44 | We see class: 45 | 46 | --- 47 | 48 | Code 49 | prop_miss_row(NULL) 50 | Condition 51 | Error in `prop_miss_row()`: 52 | ! Input must not be NULL 53 | Input is 54 | 55 | --- 56 | 57 | Code 58 | prop_complete_row(numeric(0)) 59 | Condition 60 | Error in `prop_complete_row()`: 61 | ! Input must inherit from 62 | We see class: 63 | 64 | --- 65 | 66 | Code 67 | prop_complete_row(NULL) 68 | Condition 69 | Error in `prop_complete_row()`: 70 | ! Input must not be NULL 71 | Input is 72 | 73 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/replace-with-na-scoped-var.md: -------------------------------------------------------------------------------- 1 | # empty call provides an error 2 | 3 | Code 4 | replace_with_na_all(df) 5 | Condition 6 | Error in `map()`: 7 | i In index: 1. 8 | i With name: x. 9 | Caused by error: 10 | ! Failed to evaluate glue component {rlang::f_text(condition)} 11 | Caused by error in `.f()`: 12 | ! argument "condition" is missing, with no default 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/set-n-prop-miss.md: -------------------------------------------------------------------------------- 1 | # set_n_miss errors appropriately 2 | 3 | Code 4 | set_n_miss(vec, -1) 5 | Condition 6 | Error in `set_n_miss()`: 7 | ! `x` must be greater than 0 8 | `x` is -1 9 | 10 | --- 11 | 12 | Code 13 | set_n_miss(vec, "a") 14 | Condition 15 | Error in `check_is_integer()`: 16 | ! Can't convert `x` to . 17 | 18 | --- 19 | 20 | Code 21 | set_n_miss(vec, 1.5) 22 | Condition 23 | Error in `check_is_integer()`: 24 | ! Can't convert from `x` to due to loss of precision. 25 | * Locations: 1 26 | 27 | --- 28 | 29 | Code 30 | set_n_miss(vec, c(1.5, 2)) 31 | Condition 32 | Error in `set_n_miss()`: 33 | ! `x` must be length 1 34 | `x` is 1.5 and 2, and `x` has length: 2 35 | 36 | # set_prop_miss errors appropriately 37 | 38 | Code 39 | set_prop_miss(vec, -1) 40 | Condition 41 | Error in `set_prop_miss()`: 42 | ! `prop` must be between 0 and 1 43 | `prop` is -1 44 | 45 | --- 46 | 47 | Code 48 | set_prop_miss(vec, "a") 49 | Condition 50 | Error in `set_prop_miss()`: 51 | ! `prop` must be between 0 and 1 52 | `prop` is a 53 | 54 | --- 55 | 56 | Code 57 | set_prop_miss(vec, 1.5) 58 | Condition 59 | Error in `set_prop_miss()`: 60 | ! `prop` must be between 0 and 1 61 | `prop` is 1.5 62 | 63 | --- 64 | 65 | Code 66 | set_prop_miss(vec, c(1.5, 2)) 67 | Condition 68 | Error in `set_prop_miss()`: 69 | ! `x` must be length 1 70 | `x` is 1.5 and 2, and `x` has length: 2 71 | 72 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/shade.md: -------------------------------------------------------------------------------- 1 | # shade errors with NULLs 2 | 3 | Code 4 | shade(NULL) 5 | Condition 6 | Error in `shade()`: 7 | ! Input must not be NULL 8 | Input is 9 | 10 | # shade errors with objects of length 0 11 | 12 | Code 13 | shade(numeric(0)) 14 | Condition 15 | Error in `shade()`: 16 | ! input to shade must have length > 0 17 | 18 | # shade errors with list of length 0 19 | 20 | Code 21 | shade(list()) 22 | Condition 23 | Error in `shade()`: 24 | ! input to shade must have length > 0 25 | 26 | # shade returns the correct values with list columns 27 | 28 | Code 29 | shade(list(3, list(1), c(2, 3), list()), broken = 3) 30 | Condition 31 | Error in `shade()`: 32 | ! additional levels of missing are not available when shade-ing lists column 33 | 34 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/shadow-shift.md: -------------------------------------------------------------------------------- 1 | # shadow_shift returns soft deprecation warning 2 | 3 | Code 4 | shadow_shift(NULL) 5 | Condition 6 | Warning: 7 | `shadow_shift()` was deprecated in naniar 1.1.0. 8 | i Please use `impute_below()` instead. 9 | Output 10 | NULL 11 | 12 | --- 13 | 14 | Code 15 | shadow_shift(0+3i) 16 | Condition 17 | Warning: 18 | `shadow_shift()` was deprecated in naniar 1.1.0. 19 | i Please use `impute_below()` instead. 20 | Error in `impute_below()`: 21 | ! `impute_below()` does not know how to deal with data of class 22 | Check if your input is more than length one, and that you are using the right function. Perhaps you meant to apply this to many variables in a data frame? See the examples dor details on doing this with `across()` 23 | 24 | --- 25 | 26 | `shadow_shift()` was deprecated in naniar 1.1.0. 27 | i Please use `impute_below()` instead. 28 | 29 | # shadow_shift still works 30 | 31 | Code 32 | shadow_shift(NULL) 33 | Output 34 | NULL 35 | 36 | --- 37 | 38 | Code 39 | shadow_shift(0+3i) 40 | Condition 41 | Error in `impute_below()`: 42 | ! `impute_below()` does not know how to deal with data of class 43 | Check if your input is more than length one, and that you are using the right function. Perhaps you meant to apply this to many variables in a data frame? See the examples dor details on doing this with `across()` 44 | 45 | --- 46 | 47 | Code 48 | shadow_shift(miss_vec_5) 49 | Output 50 | [1] 10.000000 10.000000 9.000000 2.163794 3.000000 51 | 52 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/special-missing-values.md: -------------------------------------------------------------------------------- 1 | # recode_shadow errors when regular dataframe passed 2 | 3 | Code 4 | recode_shadow(df, temp = .where(wind == -99 ~ "bananas")) 5 | Condition 6 | Error in `recode_shadow()`: 7 | ! Input must contain a shade column. 8 | See `?shade`, `?shade`, and `?bind_shadow` 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/test-add-any-miss.R: -------------------------------------------------------------------------------- 1 | df <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 2 | 3 | test_that("add_any_miss returns a tibble", { 4 | expect_s3_class(add_any_miss(df, x), "tbl_df") 5 | }) 6 | 7 | test_that("add_any_miss respects dimensions", { 8 | expect_equal(ncol(df) + 1, ncol(add_any_miss(df, x, y))) 9 | expect_equal(nrow(df), nrow(add_any_miss(df, x, y))) 10 | }) 11 | 12 | test_that("add_any_miss adds a column with suffix 'any_miss_vars' or 'any_miss_all'", { 13 | expect_equal(names(add_any_miss(df, x, y)), c(names(df), "any_miss_vars")) 14 | expect_equal(names(add_any_miss(df)), c(names(df), "any_miss_all")) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-add-n-miss.R: -------------------------------------------------------------------------------- 1 | test_df <- data.frame(x = c(NA, 2, 3), y = c(1, NA, 3), z = c(1, 2, 3)) 2 | 3 | df_n_miss <- data.frame(n_miss_all = c(1L, 1L, 0L)) 4 | 5 | test_df_answer <- dplyr::bind_cols(test_df, df_n_miss) 6 | 7 | 8 | test_that("add_n_miss adds a column", { 9 | expect_equal(ncol(test_df) + 1, ncol(add_n_miss(test_df))) 10 | }) 11 | 12 | test_that("add_n_miss adds a column named 'n_miss_all'", { 13 | expect_equal(names(add_n_miss(test_df)), c(names(test_df), "n_miss_all")) 14 | }) 15 | 16 | test_that("add_n_miss adds a column named 'n_miss_vars' when a variable is selected", { 17 | expect_equal(names(add_n_miss(test_df, y)), c(names(test_df), "n_miss_vars")) 18 | }) 19 | 20 | test_that("add_n_miss returns the correct number", { 21 | expect_equal(add_n_miss(test_df), test_df_answer) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-add-prop-miss.R: -------------------------------------------------------------------------------- 1 | test_df <- data.frame(x = c(NA, 2, 3), y = c(1, NA, 3), z = c(1, 2, 3)) 2 | 3 | df_prop_miss <- data.frame(prop_miss_all = c(1 / 3, 1 / 3, 0)) 4 | 5 | test_df_answer <- dplyr::bind_cols(test_df, df_prop_miss) 6 | 7 | 8 | test_that("add_prop_miss adds a column", { 9 | expect_equal(ncol(test_df) + 1, ncol(add_prop_miss(test_df))) 10 | }) 11 | 12 | test_that("add_prop adds a column named 'prop_miss_all'", { 13 | expect_equal( 14 | names(add_prop_miss(test_df)), 15 | c(names(test_df), "prop_miss_all") 16 | ) 17 | }) 18 | 19 | test_that("add_prop adds a column named 'prop_miss_vars' when a variable is selected", { 20 | expect_equal( 21 | names(add_prop_miss(test_df, y)), 22 | c(names(test_df), "prop_miss_vars") 23 | ) 24 | }) 25 | 26 | test_that("add_prop_miss returns the correct number", { 27 | expect_equal(add_prop_miss(test_df), test_df_answer) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-add-shadow-shift.R: -------------------------------------------------------------------------------- 1 | test_df <- data.frame( 2 | x = c(NA, 2, 3), 3 | y = c(1, NA, 3), 4 | z = c(1, 2, 3), 5 | xi = factor(c(4, 5, 6)) 6 | ) 7 | 8 | df_prop_miss <- data.frame(prop_miss_all = c(1 / 3, 1 / 3, 0)) 9 | 10 | test_df_answer <- dplyr::bind_cols(test_df, df_prop_miss) 11 | 12 | test_that("add_shadow_shift returns a tibble", { 13 | expect_s3_class(add_shadow_shift(test_df), "tbl_df") 14 | }) 15 | 16 | test_that("add_shadow_shift doubles the number of columns when default used", { 17 | expect_equal(ncol(test_df) * 2, ncol(add_shadow_shift(test_df))) 18 | }) 19 | 20 | test_that("add_shadow_shift adds one extra columns when one var used", { 21 | expect_equal(ncol(test_df) + 1, ncol(add_shadow_shift(test_df, xi))) 22 | }) 23 | 24 | test_that("add_shadow_shift adds a column named 'xi_shift'", { 25 | expect_equal( 26 | names(add_shadow_shift(test_df, xi)), 27 | c(names(test_df), "xi_shift") 28 | ) 29 | }) 30 | 31 | test_that("add_shadow_shift adds two columns named 'xi_shift' and 'x_shift' ", { 32 | expect_equal( 33 | names(add_shadow_shift(test_df, xi, x)), 34 | c(names(test_df), "xi_shift", "x_shift") 35 | ) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-add-shadow.R: -------------------------------------------------------------------------------- 1 | dat <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 2 | 3 | test_that("add_shadow returns a tibble", { 4 | expect_s3_class(add_shadow(dat, x), "tbl_df") 5 | }) 6 | 7 | test_that("add_shadow returns a nice error message when no variables are provided", { 8 | expect_snapshot( 9 | error = TRUE, 10 | add_shadow(dat) 11 | ) 12 | }) 13 | 14 | test_that("add_shadow adds the right number of columns", { 15 | expect_equal(ncol(dat) + 1, ncol(add_shadow(dat, x))) 16 | }) 17 | 18 | test_that("add_shadow adds a column with suffix '_NA'", { 19 | expect_equal(names(add_shadow(dat, x)), c(names(dat), "x_NA")) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-all-any-na.R: -------------------------------------------------------------------------------- 1 | misses <- c(NA, NA, NA) 2 | complete <- c(1, 2, 3) 3 | mixture <- c(NA, 1, NA) 4 | 5 | df_misses <- data.frame(x = misses, y = misses) 6 | df_complete <- data.frame(x = complete, y = complete) 7 | df_mixture <- data.frame(x = mixture, y = mixture) 8 | df_mixture2 <- data.frame(x = complete, y = misses) 9 | 10 | any_not_na <- Negate(any_na) 11 | 12 | test_that("all_na returns correct response", { 13 | expect_true(all_na(misses)) 14 | expect_false(all_na(complete)) 15 | expect_false(all_na(mixture)) 16 | expect_true(all_na(df_misses)) 17 | expect_false(all_na(df_complete)) 18 | expect_false(all_na(df_mixture)) 19 | expect_false(all_na(df_mixture2)) 20 | }) 21 | 22 | test_that("all_complete returns correct response", { 23 | expect_false(all_complete(misses)) 24 | expect_true(all_complete(complete)) 25 | expect_false(all_complete(mixture)) 26 | expect_false(all_complete(df_misses)) 27 | expect_true(all_complete(df_complete)) 28 | expect_false(all_complete(df_mixture)) 29 | expect_false(all_complete(df_mixture2)) 30 | }) 31 | 32 | test_that("any_na returns correct response", { 33 | expect_true(any_na(misses)) 34 | expect_false(any_na(complete)) 35 | expect_true(any_na(mixture)) 36 | expect_true(any_na(df_misses)) 37 | expect_false(any_na(df_complete)) 38 | expect_true(any_na(df_mixture)) 39 | expect_true(any_na(df_mixture2)) 40 | }) 41 | 42 | test_that("any_complete returns correct response", { 43 | expect_false(any_complete(misses)) 44 | expect_true(any_complete(complete)) 45 | expect_true(any_complete(mixture)) 46 | expect_false(any_complete(df_misses)) 47 | expect_true(any_complete(df_complete)) 48 | expect_true(any_complete(df_mixture)) 49 | expect_false(any_complete(df_mixture2)) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-as_shadow_upset.R: -------------------------------------------------------------------------------- 1 | test_that("as_shadow_upset errors when given datasets with <= 1 variables", { 2 | expect_snapshot( 3 | error = TRUE, 4 | as_shadow_upset(diag_na(1)) 5 | ) 6 | expect_snapshot( 7 | error = TRUE, 8 | as_shadow_upset(data.frame(x = NA)) 9 | ) 10 | expect_snapshot( 11 | error = TRUE, 12 | as_shadow_upset(data.frame(numeric(0))) 13 | ) 14 | }) 15 | 16 | test_that("as_shadow_upset returns a data.frame", { 17 | expect_s3_class(as_shadow_upset(airquality), "data.frame") 18 | }) 19 | 20 | test_that("as_shadow_upset errors when given non dataframe or 0 entry", { 21 | expect_snapshot( 22 | error = TRUE, 23 | as_shadow_upset(0) 24 | ) 25 | expect_snapshot( 26 | error = TRUE, 27 | as_shadow_upset("a") 28 | ) 29 | expect_snapshot( 30 | error = TRUE, 31 | as_shadow_upset(matrix(airquality)) 32 | ) 33 | expect_snapshot( 34 | error = TRUE, 35 | as_shadow_upset(NULL) 36 | ) 37 | }) 38 | 39 | test_that("The number of rows are the same after using as_shadow_upset", { 40 | expect_equal(nrow(as_shadow_upset(airquality)), nrow(airquality)) 41 | }) 42 | 43 | test_that("The number of columns are the same after using bind_shadow", { 44 | expect_equal(ncol(as_shadow_upset(airquality)), ncol(airquality)) 45 | }) 46 | 47 | aq_u <- as_shadow_upset(airquality) 48 | test_that("as_shadow_upset returns things of type integer", { 49 | expect_true(all(purrr::map_chr(aq_u, class) == "integer")) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-cast-shadow-shift-label.R: -------------------------------------------------------------------------------- 1 | test_that("cast_shadow_shift_label returns nice error if variables aren't included", { 2 | expect_snapshot( 3 | error = TRUE, 4 | cast_shadow_shift(airquality) 5 | ) 6 | }) 7 | 8 | test_that("cast_shadow_shift_label returns a tibble", { 9 | expect_s3_class(cast_shadow_shift_label(airquality, Ozone), "tbl_df") 10 | }) 11 | 12 | test_that("cast_shadow_shift_label adds the right number of columns", { 13 | expect_equal(4, ncol(cast_shadow_shift_label(airquality, Ozone))) 14 | expect_equal(7, ncol(cast_shadow_shift_label(airquality, Ozone, Solar.R))) 15 | expect_equal( 16 | 10, 17 | ncol(cast_shadow_shift_label(airquality, Ozone, Solar.R, Temp)) 18 | ) 19 | }) 20 | 21 | test_that("cast_shadow_shift_label adds a column with suffix '_NA' AND '_shift'", { 22 | expect_equal( 23 | names(cast_shadow_shift_label(airquality, Ozone)), 24 | c("Ozone", "Ozone_NA", "Ozone_shift", "any_missing") 25 | ) 26 | expect_equal( 27 | names(cast_shadow_shift(airquality, Ozone, Solar.R)), 28 | c( 29 | "Ozone", 30 | "Solar.R", 31 | "Ozone_NA", 32 | "Solar.R_NA", 33 | "Ozone_shift", 34 | "Solar.R_shift" 35 | ) 36 | ) 37 | expect_equal( 38 | names(cast_shadow_shift(airquality, Ozone, Solar.R, Temp)), 39 | c( 40 | "Ozone", 41 | "Solar.R", 42 | "Temp", 43 | "Ozone_NA", 44 | "Solar.R_NA", 45 | "Temp_NA", 46 | "Ozone_shift", 47 | "Solar.R_shift", 48 | "Temp_shift" 49 | ) 50 | ) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-cast-shadow-shift.R: -------------------------------------------------------------------------------- 1 | test_that("cast_shadow_shift returns a tibble", { 2 | expect_s3_class(cast_shadow_shift(airquality, Ozone), "tbl_df") 3 | }) 4 | 5 | test_that("cast_shadow_shift adds the right number of columns", { 6 | expect_equal(3, ncol(cast_shadow_shift(airquality, Ozone))) 7 | expect_equal(6, ncol(cast_shadow_shift(airquality, Ozone, Solar.R))) 8 | expect_equal(9, ncol(cast_shadow_shift(airquality, Ozone, Solar.R, Temp))) 9 | }) 10 | 11 | test_that("cast_shadow_shift adds a column with suffix '_NA' AND '_shift'", { 12 | expect_equal( 13 | names(cast_shadow_shift(airquality, Ozone)), 14 | c("Ozone", "Ozone_NA", "Ozone_shift") 15 | ) 16 | expect_equal( 17 | names(cast_shadow_shift(airquality, Ozone, Solar.R)), 18 | c( 19 | "Ozone", 20 | "Solar.R", 21 | "Ozone_NA", 22 | "Solar.R_NA", 23 | "Ozone_shift", 24 | "Solar.R_shift" 25 | ) 26 | ) 27 | expect_equal( 28 | names(cast_shadow_shift(airquality, Ozone, Solar.R, Temp)), 29 | c( 30 | "Ozone", 31 | "Solar.R", 32 | "Temp", 33 | "Ozone_NA", 34 | "Solar.R_NA", 35 | "Temp_NA", 36 | "Ozone_shift", 37 | "Solar.R_shift", 38 | "Temp_shift" 39 | ) 40 | ) 41 | }) 42 | 43 | test_that("cast_shadow_shift returns nice error when variables aren't included", { 44 | expect_snapshot( 45 | error = TRUE, 46 | cast_shadow_shift(airquality) 47 | ) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-cast-shadow.R: -------------------------------------------------------------------------------- 1 | test_that("cast_shadow returns a tibble", { 2 | expect_s3_class(cast_shadow(airquality, Ozone), "tbl_df") 3 | }) 4 | 5 | test_that("cast_shadow adds the right number of columns", { 6 | expect_equal(2, ncol(cast_shadow(airquality, Ozone))) 7 | expect_equal(4, ncol(cast_shadow(airquality, Ozone, Solar.R))) 8 | expect_equal(6, ncol(cast_shadow(airquality, Ozone, Solar.R, Temp))) 9 | }) 10 | 11 | test_that("cast_shadow adds a column with suffix '_NA'", { 12 | expect_equal(names(cast_shadow(airquality, Ozone)), c("Ozone", "Ozone_NA")) 13 | expect_equal( 14 | names(cast_shadow(airquality, Ozone, Solar.R)), 15 | c("Ozone", "Solar.R", "Ozone_NA", "Solar.R_NA") 16 | ) 17 | expect_equal( 18 | names(cast_shadow(airquality, Ozone, Solar.R, Temp)), 19 | c("Ozone", "Solar.R", "Temp", "Ozone_NA", "Solar.R_NA", "Temp_NA") 20 | ) 21 | }) 22 | -------------------------------------------------------------------------------- /tests/testthat/test-defunct.R: -------------------------------------------------------------------------------- 1 | df <- tibble::tibble(x = c("A", NA)) 2 | 3 | test_that("miss_var_prop is defunct", { 4 | expect_snapshot( 5 | error = TRUE, 6 | miss_var_prop(df) 7 | ) 8 | }) 9 | 10 | test_that("complete_var_prop is defunct", { 11 | expect_snapshot( 12 | error = TRUE, 13 | complete_var_prop(df) 14 | ) 15 | }) 16 | 17 | test_that("miss_var_pct is defunct", { 18 | expect_snapshot( 19 | error = TRUE, 20 | miss_var_pct(df) 21 | ) 22 | }) 23 | 24 | test_that("complete_var_pct is defunct", { 25 | expect_snapshot( 26 | error = TRUE, 27 | complete_var_pct(df) 28 | ) 29 | }) 30 | 31 | test_that("miss_case_prop is defunct", { 32 | expect_snapshot( 33 | error = TRUE, 34 | miss_case_prop(df) 35 | ) 36 | }) 37 | 38 | test_that("complete_case_prop is defunct", { 39 | expect_snapshot( 40 | error = TRUE, 41 | complete_case_prop(df) 42 | ) 43 | }) 44 | 45 | test_that("miss_case_pct is defunct", { 46 | expect_snapshot( 47 | error = TRUE, 48 | miss_case_pct(df) 49 | ) 50 | }) 51 | 52 | test_that("complete_case_pct is defunct", { 53 | expect_snapshot( 54 | error = TRUE, 55 | complete_case_pct(df) 56 | ) 57 | }) 58 | 59 | test_that("replace_to_na is defunct", { 60 | expect_snapshot( 61 | error = TRUE, 62 | replace_to_na(df) 63 | ) 64 | }) 65 | -------------------------------------------------------------------------------- /tests/testthat/test-gather-shadow.R: -------------------------------------------------------------------------------- 1 | df <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 2 | 3 | test_that("gather_shadow returns a tibble or data.frame", { 4 | expect_s3_class(gather_shadow(df), "data.frame") 5 | expect_s3_class(gather_shadow(df), "tbl") 6 | }) 7 | 8 | test_that("gather_shadow errors when given non dataframe or 0 entry", { 9 | expect_snapshot( 10 | error = TRUE, 11 | gather_shadow(0) 12 | ) 13 | expect_snapshot( 14 | error = TRUE, 15 | gather_shadow(matrix(0)) 16 | ) 17 | expect_snapshot( 18 | error = TRUE, 19 | gather_shadow(NULL) 20 | ) 21 | }) 22 | 23 | test_that("The number of rows are the same after using gather_shadow", { 24 | expect_equal(nrow(gather_shadow(df)), nrow(df) * 2) 25 | }) 26 | 27 | test_that("There are three columns in gather_shadow", { 28 | expect_equal(ncol(gather_shadow(df)), 3) 29 | }) 30 | 31 | test_that("gather_shadow returns columns with right names", { 32 | expect_equal(names(gather_shadow(df)), c("case", "variable", "missing")) 33 | }) 34 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-case-cumsum.R: -------------------------------------------------------------------------------- 1 | # gg_miss_case_cumsum plots ---------------------------------------------------- 2 | 3 | dat <- tibble::tribble( 4 | ~air, 5 | ~wind, 6 | ~water, 7 | ~month, 8 | -99, 9 | NA, 10 | 23, 11 | 1, 12 | -98, 13 | NA, 14 | NA, 15 | 1, 16 | 25, 17 | 30, 18 | 21, 19 | 2, 20 | NA, 21 | 99, 22 | NA, 23 | 2, 24 | 23, 25 | 40, 26 | NA, 27 | 2 28 | ) 29 | 30 | gg_miss_case_cumsum_plot <- gg_miss_case_cumsum(dat) 31 | 32 | test_that("gg_miss_case_cumsum_works", { 33 | skip_on_cran() 34 | skip_on_ci() 35 | vdiffr::expect_doppelganger("gg_miss_case_cumsum", gg_miss_case_cumsum_plot) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-fct.R: -------------------------------------------------------------------------------- 1 | dat <- tibble::tribble( 2 | ~air, 3 | ~wind, 4 | ~water, 5 | ~month, 6 | -99, 7 | NA, 8 | 23, 9 | 1, 10 | -98, 11 | NA, 12 | NA, 13 | 1, 14 | 25, 15 | 30, 16 | 21, 17 | 2, 18 | NA, 19 | 99, 20 | NA, 21 | 2, 22 | 23, 23 | 40, 24 | NA, 25 | 2 26 | ) 27 | 28 | gg_miss_fct_plot <- gg_miss_fct(dat, month) 29 | 30 | test_that("gg_miss_fct works", { 31 | skip_on_cran() 32 | skip_on_ci() 33 | vdiffr::expect_doppelganger("gg_miss_fct", gg_miss_fct_plot) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-span.R: -------------------------------------------------------------------------------- 1 | dat <- tibble::tribble( 2 | ~air, 3 | ~wind, 4 | ~water, 5 | ~month, 6 | -99, 7 | NA, 8 | 23, 9 | 1, 10 | -98, 11 | NA, 12 | NA, 13 | 1, 14 | 25, 15 | 30, 16 | 21, 17 | 2, 18 | NA, 19 | 99, 20 | NA, 21 | 2, 22 | 23, 23 | 40, 24 | NA, 25 | 2 26 | ) 27 | 28 | gg_miss_span_plot <- gg_miss_span(dat, water, 3) 29 | 30 | test_that("gg_miss_span works", { 31 | skip_on_cran() 32 | skip_on_ci() 33 | vdiffr::expect_doppelganger("gg_miss_span", gg_miss_span_plot) 34 | }) 35 | 36 | gg_miss_span_plot_group <- gg_miss_span(dat, water, 3, facet = month) 37 | 38 | test_that("gg_miss_span_group works", { 39 | skip_on_cran() 40 | skip_on_ci() 41 | vdiffr::expect_doppelganger("gg_miss_span_group", gg_miss_span_plot_group) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-var-cumsum.R: -------------------------------------------------------------------------------- 1 | # gg_miss_var_cumsum plots ---------------------------------------------------- 2 | 3 | dat <- tibble::tribble( 4 | ~air, 5 | ~wind, 6 | ~water, 7 | ~month, 8 | -99, 9 | NA, 10 | 23, 11 | 1, 12 | -98, 13 | NA, 14 | NA, 15 | 1, 16 | 25, 17 | 30, 18 | 21, 19 | 2, 20 | NA, 21 | 99, 22 | NA, 23 | 2, 24 | 23, 25 | 40, 26 | NA, 27 | 2 28 | ) 29 | 30 | gg_miss_var_cumsum_plot <- gg_miss_var_cumsum(dat) 31 | 32 | test_that("gg_miss_var_cumsum_works", { 33 | skip_on_cran() 34 | skip_on_ci() 35 | vdiffr::expect_doppelganger("gg_miss_var_cumsum", gg_miss_var_cumsum_plot) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-var-plot.R: -------------------------------------------------------------------------------- 1 | # gg_miss_var plots ------------------------------------------------------------ 2 | 3 | dat <- tibble::tribble( 4 | ~air, 5 | ~wind, 6 | ~water, 7 | ~month, 8 | -99, 9 | NA, 10 | 23, 11 | 1, 12 | -98, 13 | NA, 14 | NA, 15 | 1, 16 | 25, 17 | 30, 18 | 21, 19 | 2, 20 | NA, 21 | 99, 22 | NA, 23 | 2, 24 | 23, 25 | 40, 26 | NA, 27 | 2 28 | ) 29 | 30 | gg_miss_var_plot <- gg_miss_var(dat) 31 | 32 | test_that("gg_miss_var_works", { 33 | skip_on_cran() 34 | skip_on_ci() 35 | vdiffr::expect_doppelganger("gg_miss_var", gg_miss_var_plot) 36 | }) 37 | 38 | gg_miss_var_plot_group <- gg_miss_var(dat, facet = month) 39 | 40 | test_that("gg_miss_var_group_works", { 41 | skip_on_cran() 42 | skip_on_ci() 43 | vdiffr::expect_doppelganger("gg_miss_var_plot_group", gg_miss_var_plot_group) 44 | }) 45 | 46 | 47 | gg_miss_var_plot_pct <- gg_miss_var(dat, show_pct = TRUE) 48 | 49 | test_that("gg_miss_var_pct_works", { 50 | skip_on_cran() 51 | skip_on_ci() 52 | vdiffr::expect_doppelganger("gg_miss_var_pct", gg_miss_var_plot_pct) 53 | }) 54 | 55 | gg_miss_var_plot_group_pct <- gg_miss_var(dat, facet = month, show_pct = TRUE) 56 | 57 | test_that("gg_miss_var_works", { 58 | skip_on_cran() 59 | skip_on_ci() 60 | vdiffr::expect_doppelganger( 61 | "gg_miss_var_group_pct", 62 | gg_miss_var_plot_group_pct 63 | ) 64 | }) 65 | -------------------------------------------------------------------------------- /tests/testthat/test-gg-miss-which.R: -------------------------------------------------------------------------------- 1 | dat <- tibble::tribble( 2 | ~air, 3 | ~wind, 4 | ~water, 5 | ~month, 6 | -99, 7 | NA, 8 | 23, 9 | 1, 10 | -98, 11 | NA, 12 | NA, 13 | 1, 14 | 25, 15 | 30, 16 | 21, 17 | 2, 18 | NA, 19 | 99, 20 | NA, 21 | 2, 22 | 23, 23 | 40, 24 | NA, 25 | 2 26 | ) 27 | 28 | gg_miss_which_plot <- gg_miss_which(dat) 29 | 30 | test_that("gg_miss_which_works", { 31 | skip_on_cran() 32 | skip_on_ci() 33 | vdiffr::expect_doppelganger("gg_miss_which", gg_miss_which_plot) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-gg_miss_upset.R: -------------------------------------------------------------------------------- 1 | # context("test-gg-miss-upset") 2 | # 3 | # gg_miss_upset_plot <- gg_miss_upset(riskfactors) 4 | # 5 | # test_that("gg_miss_upset works",{ 6 | # skip_on_cran() 7 | # skip_on_appveyor() 8 | # skip_on_travis() 9 | # skip_on_gh_actions() 10 | # vdiffr::expect_doppelganger("gg_miss_upset", 11 | # gg_miss_upset_plot) 12 | # }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-impute-below-at.R: -------------------------------------------------------------------------------- 1 | miss_vec <- rnorm(100) 2 | 3 | # add 20 missing values 4 | miss_vec[sample(1:100, 20)] <- NA 5 | 6 | miss_df <- data.frame(miss_vec) 7 | 8 | test_that("impute_below_at leaves no NA values", { 9 | expect_false( 10 | anyNA(impute_below_at(miss_df, "miss_vec")[ 11 | which(is.na(miss_df$miss_vec)), 12 | ]) 13 | ) 14 | }) 15 | 16 | test_that("impute_below_at works with vars", { 17 | expect_false( 18 | anyNA(impute_below_at(miss_df, dplyr::vars(miss_vec))[ 19 | which(is.na(miss_df$miss_vec)), 20 | ]) 21 | ) 22 | }) 23 | 24 | miss_vec <- rnorm(100) 25 | 26 | # add 20 missing values 27 | miss_vec[sample(1:100, 20)] <- NA 28 | 29 | miss_df <- data.frame(miss_vec) 30 | 31 | test_that("impute_below_if leaves no NA values", { 32 | expect_false( 33 | anyNA(impute_below_if(airquality, .predicate = is.numeric)) 34 | ) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-impute-factor.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | vec <- factor(x = c(NA, LETTERS[1:4])) 3 | 4 | vec2 <- factor(x = c("wat", LETTERS[1:4])) 5 | 6 | chick <- chickwts %>% 7 | mutate( 8 | feed = set_prop_miss(feed, prop = 0.2) 9 | ) 10 | chick_shadow <- nabular(chick) 11 | 12 | test_that("impute_factor works", { 13 | expect_equal(impute_factor(vec, "wat"), vec2) 14 | }) 15 | 16 | ## impute_factor_across -------------------------------------------------------- 17 | test_that("impute_factor works with across", { 18 | expect_false( 19 | mutate(chick, across(where(is.factor), \(x) impute_factor(x, "wat"))) %>% 20 | all_na() 21 | ) 22 | }) 23 | 24 | test_that("impute_factor works with across and nabular", { 25 | expect_false( 26 | mutate( 27 | chick_shadow, 28 | across(where(is.factor), \(x) impute_factor(x, "wat")) 29 | ) %>% 30 | all_na() 31 | ) 32 | }) 33 | 34 | test_that("impute_factor retains proper shadow values when used with across", { 35 | expect_equal( 36 | unbind_data( 37 | mutate( 38 | chick_shadow, 39 | across(where(is.factor), \(x) impute_factor(x, "wat")) 40 | ) 41 | ), 42 | unbind_data( 43 | chick_shadow 44 | ) 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-impute-fixed.R: -------------------------------------------------------------------------------- 1 | vec <- rnorm(10) 2 | 3 | vec[sample(1:10, 3)] <- NA 4 | 5 | fixed_val <- -99 6 | 7 | vec2 <- vec 8 | 9 | vec2[is.na(vec)] <- fixed_val 10 | 11 | aq_shadow <- nabular(airquality) 12 | 13 | test_that("impute_fixed works", { 14 | expect_equal(impute_fixed(vec, -99), vec2) 15 | }) 16 | 17 | ## impute_fixed_across -------------------------------------------------------- 18 | library(dplyr) 19 | test_that("impute_fixed works with across", { 20 | expect_false( 21 | mutate(airquality, across(where(is.numeric), \(x) impute_fixed(x, -99))) %>% 22 | all_na() 23 | ) 24 | }) 25 | 26 | test_that("impute_fixed works with across and nabular", { 27 | expect_false( 28 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_fixed(x, -99))) %>% 29 | all_na() 30 | ) 31 | }) 32 | 33 | test_that("impute_fixed retains proper shadow values when used with across", { 34 | expect_equal( 35 | unbind_data( 36 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_fixed(x, -99))) 37 | ), 38 | unbind_data( 39 | aq_shadow 40 | ) 41 | ) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-impute-mode.R: -------------------------------------------------------------------------------- 1 | vec <- rnorm(10) 2 | 3 | vec[sample(1:10, 3)] <- NA 4 | 5 | vec2 <- vec 6 | 7 | vec2[is.na(vec)] <- the_mode(vec, na.rm = TRUE) 8 | 9 | aq_shadow <- nabular(airquality) 10 | 11 | test_that("impute_mode works", { 12 | expect_equal(impute_mode(vec), vec2) 13 | }) 14 | 15 | ## impute_mode_across -------------------------------------------------------- 16 | library(dplyr) 17 | test_that("impute_mode works with across", { 18 | expect_false( 19 | mutate(airquality, across(where(is.numeric), \(x) impute_mode(x))) %>% 20 | all_na() 21 | ) 22 | }) 23 | 24 | test_that("impute_mode works with across and nabular", { 25 | expect_false( 26 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_mode(x))) %>% 27 | all_na() 28 | ) 29 | }) 30 | 31 | test_that("impute_mode retains proper shadow values when used with across", { 32 | expect_equal( 33 | unbind_data( 34 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_mode(x))) 35 | ), 36 | unbind_data( 37 | aq_shadow 38 | ) 39 | ) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-impute-zero.R: -------------------------------------------------------------------------------- 1 | vec <- rnorm(10) 2 | 3 | vec[sample(1:10, 3)] <- NA 4 | 5 | vec2 <- vec 6 | 7 | vec2[is.na(vec)] <- 0 8 | 9 | aq_shadow <- nabular(airquality) 10 | 11 | test_that("impute_zero works", { 12 | expect_equal(impute_zero(vec), vec2) 13 | }) 14 | 15 | ## impute_zero_across -------------------------------------------------------- 16 | library(dplyr) 17 | test_that("impute_zero works with across", { 18 | expect_false( 19 | mutate(airquality, across(where(is.numeric), \(x) impute_zero(x))) %>% 20 | all_na() 21 | ) 22 | }) 23 | 24 | test_that("impute_zero works with across and nabular", { 25 | expect_false( 26 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_zero(x))) %>% 27 | all_na() 28 | ) 29 | }) 30 | 31 | test_that("impute_zero retains proper shadow values when used with across", { 32 | expect_equal( 33 | unbind_data( 34 | mutate(aq_shadow, across(where(is.numeric), \(x) impute_zero(x))) 35 | ), 36 | unbind_data( 37 | aq_shadow 38 | ) 39 | ) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-label-miss-1d.R: -------------------------------------------------------------------------------- 1 | test_df <- data.frame(x = c(NA, 2, 3), y = c(1, NA, 3), z = c(1, 2, 3)) 2 | 3 | test_that("label_miss_1d errors on a NULL entry", { 4 | expect_snapshot( 5 | error = TRUE, 6 | label_miss_1d(NULL) 7 | ) 8 | }) 9 | 10 | test_that("label_miss_1d returns a vector of the same length as the input", { 11 | expect_length(label_miss_1d(test_df$x), nrow(test_df)) 12 | }) 13 | 14 | test_that("label_miss_1d returns factor vector", { 15 | expect_type( 16 | label_miss_1d(test_df$x), 17 | # typeof(factor()) is "integer" 18 | "integer" 19 | ) 20 | }) 21 | 22 | test_that("label_miss_1d identifies the correct location of missingness", { 23 | expect_snapshot( 24 | label_miss_1d(test_df$x) 25 | ) 26 | expect_snapshot( 27 | label_miss_1d(test_df$y) 28 | ) 29 | expect_snapshot( 30 | label_miss_1d(test_df$z) 31 | ) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-label-miss-2d.R: -------------------------------------------------------------------------------- 1 | test_df <- data.frame(x = c(NA, 2, 3), y = c(1, NA, 3), z = c(1, 2, 3)) 2 | 3 | test_that("label_miss_2d errors on the first NULL entry", { 4 | expect_snapshot( 5 | error = TRUE, 6 | label_miss_2d(NULL, 3) 7 | ) 8 | }) 9 | 10 | test_that("label_miss_2d errors on the second NULL entry", { 11 | expect_snapshot( 12 | error = TRUE, 13 | label_miss_2d(3, NULL) 14 | ) 15 | }) 16 | 17 | test_that("label_miss_2d errors when both are NULL", { 18 | expect_snapshot( 19 | error = TRUE, 20 | label_miss_2d(NULL, NULL) 21 | ) 22 | }) 23 | 24 | test_that("label_miss_2d returns a vector of the same length as the input", { 25 | expect_length( 26 | label_miss_2d(test_df$x, test_df$y), 27 | nrow(test_df) 28 | ) 29 | }) 30 | 31 | test_that("label_miss_2d returns factor vector", { 32 | expect_type( 33 | label_miss_2d(test_df$x, test_df$y), 34 | # typeof(factor()) is "integer" 35 | "integer" 36 | ) 37 | }) 38 | 39 | 40 | test_that("label_miss_2d identifies the correct location of missingness", { 41 | expect_snapshot( 42 | label_miss_2d(test_df$x, test_df$y) 43 | ) 44 | expect_snapshot( 45 | label_miss_2d(test_df$y, test_df$z) 46 | ) 47 | expect_snapshot( 48 | label_miss_2d(test_df$x, test_df$z) 49 | ) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-label-shadow.R: -------------------------------------------------------------------------------- 1 | test_that("label_shadow returns character", { 2 | expect_type(label_shadow(airquality), "character") 3 | }) 4 | 5 | test_that("label_shadow adds the right number of elements", { 6 | expect_equal(nrow(airquality), length(label_shadow(airquality))) 7 | }) 8 | 9 | aq_shadow <- airquality %>% add_shadow(Ozone) 10 | 11 | test_that("label_shadow contains 'Not Missing' and 'Missing'", { 12 | expect_equal(unique(label_shadow(aq_shadow)), c("Not Missing", "Missing")) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-mcar-test.R: -------------------------------------------------------------------------------- 1 | test_that("mcar_test calculates correct statistics", { 2 | out_test <- mcar_test(airquality) 3 | 4 | expect_equal(out_test[["statistic"]], 35.1061288689702) 5 | expect_equal(out_test[["df"]], 14) 6 | expect_equal(out_test[["p.value"]], 0.00141778113856683) 7 | expect_equal(out_test[["missing.patterns"]], 4L) 8 | }) 9 | 10 | test_that("mcar_test works when one of the missing patterns is all NAs", { 11 | airquality_all_missing <- dplyr::add_row(airquality, Ozone = NA) 12 | 13 | out_test <- mcar_test(airquality_all_missing) 14 | 15 | expect_equal(out_test[["statistic"]], 35.1061229683641) 16 | expect_equal(out_test[["missing.patterns"]], 5L) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-case-table.R: -------------------------------------------------------------------------------- 1 | test_that("miss_case_table errors when given wrong type", { 2 | expect_snapshot( 3 | error = TRUE, 4 | miss_case_table(NULL) 5 | ) 6 | expect_snapshot( 7 | error = TRUE, 8 | miss_case_table(1) 9 | ) 10 | expect_snapshot( 11 | error = TRUE, 12 | miss_case_table("a") 13 | ) 14 | expect_snapshot( 15 | error = TRUE, 16 | miss_case_table(matrix(0)) 17 | ) 18 | }) 19 | 20 | aq_group <- dplyr::group_by(airquality, Month) 21 | 22 | test_that("miss_case_table produces a tibble", { 23 | expect_s3_class(miss_case_table(airquality), "tbl_df") 24 | expect_s3_class(miss_case_table(aq_group), "tbl_df") 25 | }) 26 | 27 | test_that("grouped_df returns 1 more column than regular miss_case_table", { 28 | expect_equal( 29 | ncol(miss_case_table(aq_group)), 30 | ncol(miss_case_table(airquality)) + 1 31 | ) 32 | }) 33 | 34 | test_that("grouped_df returns a column named 'Month'", { 35 | expect_identical( 36 | names(miss_case_table(aq_group)), 37 | c("Month", "n_miss_in_case", "n_cases", "pct_cases") 38 | ) 39 | }) 40 | 41 | test_that("grouped_df returns a dataframe with more rows than regular", { 42 | expect_gt( 43 | nrow(miss_case_table(aq_group)), 44 | nrow(miss_case_table(airquality)) 45 | ) 46 | }) 47 | 48 | test_that("grouped_df returns a column named 'Month' with the right levels", { 49 | expect_identical( 50 | unique(miss_case_table(aq_group)$Month), 51 | 5:9 52 | ) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-scan-count.R: -------------------------------------------------------------------------------- 1 | dat_ms <- tibble::tribble( 2 | ~x, 3 | ~y, 4 | ~z, 5 | 1, 6 | "A", 7 | -100, 8 | 3, 9 | "N/A", 10 | -99, 11 | NA, 12 | NA, 13 | -98, 14 | -99, 15 | "E", 16 | -101, 17 | -98, 18 | "F", 19 | -1 20 | ) 21 | test_that("miss_scan_count returns a data.frame", { 22 | expect_s3_class(miss_scan_count(dat_ms, -99), "data.frame") 23 | }) 24 | 25 | test_that("miss_scan_count returns an error when no search is provided", { 26 | expect_snapshot( 27 | error = TRUE, 28 | miss_scan_count(dat_ms) 29 | ) 30 | }) 31 | 32 | test_that("miss_scan_count returns an error when no data is provided", { 33 | expect_snapshot( 34 | error = TRUE, 35 | miss_scan_count(search = -99) 36 | ) 37 | }) 38 | 39 | test_that("miss_scan_count returns a data.frame of the right size", { 40 | expect_equal( 41 | dim(miss_scan_count(dat_ms, -99)), 42 | c(3, 2) 43 | ) 44 | }) 45 | 46 | correct_answer_1 <- tibble::tribble( 47 | ~Variable, 48 | ~n, 49 | "x", 50 | 1L, 51 | "y", 52 | 0L, 53 | "z", 54 | 1L 55 | ) 56 | 57 | correct_answer_2 <- tibble::tribble( 58 | ~Variable, 59 | ~n, 60 | "x", 61 | 2L, 62 | "y", 63 | 0L, 64 | "z", 65 | 2L 66 | ) 67 | 68 | correct_answer_3 <- tibble::tribble( 69 | ~Variable, 70 | ~n, 71 | "x", 72 | 2L, 73 | "y", 74 | 1L, 75 | "z", 76 | 2L 77 | ) 78 | 79 | correct_answer_4 <- tibble::tribble( 80 | ~Variable, 81 | ~n, 82 | "x", 83 | 2L, 84 | "y", 85 | 1L, 86 | "z", 87 | 2L 88 | ) 89 | 90 | test_that("miss_scan_count returns the right answer", { 91 | expect_equal(miss_scan_count(dat_ms, -99), correct_answer_1) 92 | expect_equal(miss_scan_count(dat_ms, c(-99, -98)), correct_answer_2) 93 | }) 94 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-summary.R: -------------------------------------------------------------------------------- 1 | test_that("miss_summary returns a data.frame", { 2 | expect_s3_class( 3 | miss_summary(airquality), 4 | "data.frame" 5 | ) 6 | }) 7 | 8 | test_that("miss_summary returns a tibble", { 9 | expect_equal( 10 | class(miss_summary(airquality)), 11 | c("tbl_df", "tbl", "data.frame") 12 | ) 13 | }) 14 | 15 | test_that("miss_summary errors when given non dataframe or 0 entry", { 16 | expect_snapshot( 17 | error = TRUE, 18 | miss_summary(0) 19 | ) 20 | expect_snapshot( 21 | error = TRUE, 22 | miss_summary("a") 23 | ) 24 | expect_snapshot( 25 | error = TRUE, 26 | miss_summary(matrix(airquality)) 27 | ) 28 | expect_snapshot( 29 | error = TRUE, 30 | miss_summary(NULL) 31 | ) 32 | }) 33 | 34 | test_that("There are 7 columns", { 35 | expect_equal(ncol(miss_summary(airquality)), 7) 36 | }) 37 | 38 | test_that("The columns are named correctly", { 39 | expect_named( 40 | miss_summary(airquality), 41 | c( 42 | "miss_df_prop", 43 | "miss_var_prop", 44 | "miss_case_prop", 45 | "miss_case_table", 46 | "miss_var_table", 47 | "miss_var_summary", 48 | "miss_case_summary" 49 | ) 50 | ) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-var-case-cumsum.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | test_that("miss_var_cumsum gives warning", { 3 | expect_snapshot_warning( 4 | miss_var_cumsum(airquality) 5 | ) 6 | }) 7 | 8 | test_that("miss_var_cumsum gives warning with grouping", { 9 | expect_snapshot_warning( 10 | miss_var_cumsum(group_by(airquality, Month)) 11 | ) 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-var-run.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | 3 | p_group <- pedestrian %>% group_by(month) 4 | 5 | test_that("miss_var_run doesn't return a warning", { 6 | expect_silent(miss_var_run(data = pedestrian, var = hourly_counts)) 7 | expect_silent(miss_var_run(data = p_group, var = hourly_counts)) 8 | }) 9 | 10 | mvr <- miss_var_run(data = pedestrian, var = hourly_counts) 11 | 12 | mvr_g <- miss_var_run(data = p_group, var = hourly_counts) 13 | 14 | test_that("miss_var_run is a tbl", { 15 | expect_equal(class(mvr), c("tbl_df", "tbl", "data.frame")) 16 | expect_equal(class(mvr_g), c("grouped_df", "tbl_df", "tbl", "data.frame")) 17 | }) 18 | 19 | test_that("miss_var_run returns right dimensions", { 20 | expect_equal(ncol(mvr), 2) 21 | expect_equal(nrow(mvr), 35) 22 | expect_equal(ncol(mvr_g), 3) 23 | expect_equal(nrow(mvr_g), 51) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-var-span.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | 3 | p_group <- pedestrian %>% group_by(month) 4 | 5 | test_that("miss_var_span doesn't return a warning", { 6 | expect_silent(miss_var_span( 7 | data = pedestrian, 8 | var = hourly_counts, 9 | span_every = 168 10 | )) 11 | expect_silent(miss_var_span( 12 | data = p_group, 13 | var = hourly_counts, 14 | span_every = 168 15 | )) 16 | }) 17 | 18 | mvs <- miss_var_span(data = pedestrian, var = hourly_counts, span_every = 168) 19 | 20 | mvs_g <- miss_var_span(data = p_group, var = hourly_counts, span_every = 168) 21 | 22 | test_that("miss_var_span is a tbl", { 23 | expect_equal(class(mvs), c("tbl_df", "tbl", "data.frame")) 24 | expect_equal(class(mvs_g), c("grouped_df", "tbl_df", "tbl", "data.frame")) 25 | }) 26 | 27 | test_that("miss_var_span returns right dimensions", { 28 | expect_equal(ncol(mvs), 6) 29 | expect_equal(nrow(mvs), 225) 30 | expect_equal(ncol(mvs_g), 7) 31 | expect_equal(nrow(mvs_g), 230) 32 | }) 33 | 34 | test_that("miss_var_span n_miss + n_complete returns the number of rows", { 35 | test <- miss_var_span(pedestrian, var = hourly_counts, span_every = 4000) 36 | 37 | totals <- sum(test$n_miss) + sum(test$n_complete) 38 | 39 | expect_equal(totals, nrow(pedestrian)) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-miss-var-which.R: -------------------------------------------------------------------------------- 1 | test_that("miss-var-which returns the right variables", { 2 | expect_equal(miss_var_which(airquality), c("Ozone", "Solar.R")) 3 | }) 4 | 5 | test_that("miss-var-which errors on NULL", { 6 | expect_snapshot( 7 | error = TRUE, 8 | miss_var_which(NULL) 9 | ) 10 | }) 11 | 12 | test_that("miss-var-which returns null when no missings", { 13 | expect_null(miss_var_which(iris)) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-n-complete.R: -------------------------------------------------------------------------------- 1 | test_that("n_complete handles 0 cases as I expect", { 2 | expect_equal(n_complete(0), 1) 3 | 4 | expect_equal(n_complete(numeric(0)), 0) 5 | 6 | expect_equal(n_complete(iris[0]), 0) 7 | }) 8 | 9 | test_that("n_complete correctly counts the number of missings", { 10 | expect_equal(n_complete(c(0, NA, 120, NA)), 2) 11 | expect_equal(n_complete(c(NA, NA, NA, NA)), 0) 12 | expect_equal(n_complete(c(1, 2, 3, 4, 5)), 5) 13 | }) 14 | 15 | test_that("n_complete works for dataframes", { 16 | expect_equal(n_complete(airquality), 874) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-n-miss.R: -------------------------------------------------------------------------------- 1 | test_that("n_miss handles 0 cases as I expect", { 2 | expect_equal(n_miss(0), 0) 3 | expect_equal(n_miss(numeric(0)), 0) 4 | expect_equal(n_miss(mtcars[0]), 0) 5 | }) 6 | 7 | test_that("n_miss correctly counts the number of missings", { 8 | expect_equal(n_miss(c(0, NA, 120, NA)), 2) 9 | expect_equal(n_miss(c(NA, NA, NA, NA)), 4) 10 | expect_equal(n_miss(c(1, 2, 3, 4, 5)), 0) 11 | }) 12 | 13 | test_that("n_miss works for dataframes", { 14 | expect_equal(n_miss(airquality), 44) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-prop-complete.R: -------------------------------------------------------------------------------- 1 | df <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 2 | 3 | 4 | test_that("prop_complete handles 0 cases as I expect", { 5 | expect_equal(prop_complete(0), 1) 6 | expect_equal(prop_complete(TRUE), 1) 7 | expect_equal(prop_complete("TRUE"), 1) 8 | expect_equal(prop_complete(numeric(0)), NaN) 9 | 10 | expect_equal(prop_complete(iris[0]), NaN) 11 | }) 12 | 13 | test_that("prop_complete correctly counts the proportion of missings", { 14 | expect_equal(prop_complete(c(0, NA, 120, NA)), 0.5) 15 | expect_equal(prop_complete(c(NA, NA, 120, NA)), 0.25) 16 | expect_equal(prop_complete(c(NA, NA, NA, NA)), 0) 17 | expect_equal(prop_complete(c(1, 2, 3, 4, 5)), 1) 18 | }) 19 | 20 | df <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 21 | 22 | test_that("prop_complete works for dataframes", { 23 | expect_true(dplyr::near(round(prop_complete(df), 5), 0.7)) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-prop-miss.R: -------------------------------------------------------------------------------- 1 | test_that("prop_miss handles 0 cases as I expect", { 2 | expect_equal(prop_miss(0), 0) 3 | expect_equal(prop_miss(TRUE), 0) 4 | expect_equal(prop_miss(numeric(0)), NaN) 5 | 6 | expect_equal(prop_miss(iris[0]), NaN) 7 | }) 8 | 9 | test_that("prop_miss correctly counts the proportion of missings", { 10 | expect_equal(prop_miss(c(0, NA, 120, NA)), 0.5) 11 | expect_equal(prop_miss(c(NA, NA, 120, NA)), 0.75) 12 | expect_equal(prop_miss(c(NA, NA, NA, NA)), 1) 13 | expect_equal(prop_miss(c(1, 2, 3, 4, 5)), 0) 14 | }) 15 | 16 | test_that("prop_miss works for dataframes", { 17 | expect_true(dplyr::near(round(prop_miss(airquality), 5), 0.047930)) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-prop_row.R: -------------------------------------------------------------------------------- 1 | # is there a more general way to write these kinds of tests? 2 | test_that("rowwise errors for non data frames", { 3 | expect_snapshot( 4 | error = TRUE, 5 | n_miss_row(numeric(0)) 6 | ) 7 | expect_snapshot( 8 | error = TRUE, 9 | n_miss_row(NULL) 10 | ) 11 | expect_snapshot( 12 | error = TRUE, 13 | n_complete_row(numeric(0)) 14 | ) 15 | expect_snapshot( 16 | error = TRUE, 17 | n_complete_row(NULL) 18 | ) 19 | expect_snapshot( 20 | error = TRUE, 21 | prop_miss_row(numeric(0)) 22 | ) 23 | expect_snapshot( 24 | error = TRUE, 25 | prop_miss_row(NULL) 26 | ) 27 | expect_snapshot( 28 | error = TRUE, 29 | prop_complete_row(numeric(0)) 30 | ) 31 | expect_snapshot( 32 | error = TRUE, 33 | prop_complete_row(NULL) 34 | ) 35 | }) 36 | 37 | d10 <- diag_na(10) 38 | ds <- d10 39 | ds[upper.tri(ds)] <- NA 40 | 41 | test_that("n/prop_miss_row correctly counts the missings", { 42 | expect_equal(n_miss_row(d10), rep(1, 10)) 43 | expect_equal(n_miss_row(ds), 10:1) 44 | expect_equal(prop_miss_row(d10), rep(0.1, 10)) 45 | expect_equal(prop_miss_row(ds), rev(seq(from = 0.1, to = 1, by = 0.1))) 46 | }) 47 | 48 | test_that("n/prop_complete_row correctly counts the missings", { 49 | expect_equal(n_complete_row(d10), rep(9, 10)) 50 | expect_equal(n_complete_row(ds), 0:9) 51 | expect_equal(prop_complete_row(d10), rep(0.9, 10)) 52 | expect_equal(prop_complete_row(ds), seq(from = 0.0, to = 0.9, by = 0.1)) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test-replace_na_with.R: -------------------------------------------------------------------------------- 1 | vec <- rnorm(10) 2 | 3 | vec[sample(1:10, 3)] <- NA 4 | 5 | fixed_val <- -99 6 | 7 | vec2 <- vec 8 | 9 | vec2[is.na(vec)] <- fixed_val 10 | 11 | aq_shadow <- nabular(airquality) 12 | 13 | test_that("replace_na_with works", { 14 | expect_equal(replace_na_with(vec, -99), vec2) 15 | }) 16 | 17 | ## replace_na_with_across -------------------------------------------------------- 18 | library(dplyr) 19 | test_that("replace_na_with works with across", { 20 | expect_false( 21 | mutate( 22 | airquality, 23 | across(where(is.numeric), \(x) replace_na_with(x, -99)) 24 | ) %>% 25 | all_na() 26 | ) 27 | }) 28 | 29 | test_that("replace_na_with works with across and nabular", { 30 | expect_false( 31 | mutate( 32 | aq_shadow, 33 | across(where(is.numeric), \(x) replace_na_with(x, -99)) 34 | ) %>% 35 | all_na() 36 | ) 37 | }) 38 | 39 | test_that("replace_na_with retains proper shadow values when used with across", { 40 | expect_equal( 41 | unbind_data( 42 | mutate(aq_shadow, across(where(is.numeric), \(x) replace_na_with(x, -99))) 43 | ), 44 | unbind_data( 45 | aq_shadow 46 | ) 47 | ) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-set-n-prop-miss.R: -------------------------------------------------------------------------------- 1 | vec <- 1:10 2 | 3 | test_that("set_n_miss works", { 4 | expect_equal(n_miss(set_n_miss(vec, 1)), 1) 5 | expect_equal(n_miss(set_n_miss(vec, 5)), 5) 6 | expect_equal(n_miss(set_n_miss(vec, 10)), 10) 7 | expect_equal(n_miss(set_n_miss(vec, 0)), 0) 8 | }) 9 | 10 | test_that("set_prop_miss works", { 11 | expect_equal(prop_miss(set_prop_miss(vec, 0.1)), .1) 12 | expect_equal(prop_miss(set_prop_miss(vec, 0.5)), .5) 13 | expect_equal(prop_miss(set_prop_miss(vec, 1)), 1) 14 | expect_equal(prop_miss(set_prop_miss(vec, 0)), 0) 15 | }) 16 | 17 | test_that("set_n_miss errors appropriately", { 18 | expect_snapshot( 19 | error = TRUE, 20 | set_n_miss(vec, -1) 21 | ) 22 | expect_snapshot( 23 | error = TRUE, 24 | set_n_miss(vec, "a") 25 | ) 26 | expect_snapshot( 27 | error = TRUE, 28 | set_n_miss(vec, 1.5) 29 | ) 30 | expect_snapshot( 31 | error = TRUE, 32 | set_n_miss(vec, c(1.5, 2)) 33 | ) 34 | }) 35 | 36 | test_that("set_prop_miss errors appropriately", { 37 | expect_snapshot( 38 | error = TRUE, 39 | set_prop_miss(vec, -1) 40 | ) 41 | expect_snapshot( 42 | error = TRUE, 43 | set_prop_miss(vec, "a") 44 | ) 45 | expect_snapshot( 46 | error = TRUE, 47 | set_prop_miss(vec, 1.5) 48 | ) 49 | expect_snapshot( 50 | error = TRUE, 51 | set_prop_miss(vec, c(1.5, 2)) 52 | ) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test-shade-verifiers.R: -------------------------------------------------------------------------------- 1 | x <- c(NA, 1, 2, "3") 2 | xs <- shade(c(NA, 1, 2, "3")) 3 | aq <- airquality 4 | aq_s <- as_shadow(airquality) 5 | 6 | test_that("is_shade returns appropriate output", { 7 | expect_true(is_shade(xs)) 8 | expect_false(is_shade(x)) 9 | expect_false(is_shade(aq_s)) 10 | expect_false(is_shade(aq)) 11 | }) 12 | 13 | test_that("are_shade returns appropriate output", { 14 | expect_true(all(are_shade(xs))) 15 | expect_false(all(are_shade(x))) 16 | expect_true(all(are_shade(aq_s))) 17 | expect_false(all(are_shade(aq))) 18 | }) 19 | 20 | test_that("any_shade returns appropriate output", { 21 | expect_true(any_shade(xs)) 22 | expect_false(any_shade(x)) 23 | expect_true(any_shade(aq_s)) 24 | expect_false(any_shade(aq)) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-shadow-expand-relevel.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | 3 | df_sh <- data.frame( 4 | Q1 = c("yes", "no", "no", NA), 5 | Q2 = c("a", NA, NA, NA), 6 | Q3 = c(1, NA, NA, 4) 7 | ) %>% 8 | mutate(Q1 = factor(Q1)) %>% 9 | mutate(Q2 = factor(Q2)) %>% 10 | nabular() 11 | 12 | test_that(desc = "when levels are repeated, they don't fail", { 13 | df_sh_recode_q2 <- df_sh %>% 14 | recode_shadow(Q2 = .where(Q1 %in% "no" ~ "skip")) 15 | 16 | expect_equal(levels(df_sh_recode_q2$Q2_NA), c("!NA", "NA", "NA_skip")) 17 | 18 | df_sh_recode_q3 <- df_sh_recode_q2 %>% 19 | recode_shadow(Q3 = .where(Q1 %in% "no" ~ "skip")) 20 | 21 | expect_equal(levels(df_sh_recode_q3$Q3_NA), c("!NA", "NA", "NA_skip")) 22 | 23 | q1_na_fct_vals <- df_sh_recode_q3$Q1_NA %>% 24 | table(., useNA = "always") %>% 25 | as.numeric() 26 | 27 | q2_na_fct_vals <- df_sh_recode_q3$Q2_NA %>% 28 | table(., useNA = "always") %>% 29 | as.numeric() 30 | 31 | q3_na_fct_vals <- df_sh_recode_q3$Q3_NA %>% 32 | table(., useNA = "always") %>% 33 | as.numeric() 34 | 35 | expect_equal(q1_na_fct_vals, c(3, 1, 0, 0)) 36 | expect_equal(q2_na_fct_vals, c(1, 1, 2, 0)) 37 | expect_equal(q3_na_fct_vals, c(2, 0, 2, 0)) 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-shadow-identifiers.R: -------------------------------------------------------------------------------- 1 | df <- tibble::tribble( 2 | ~wind, 3 | ~temp, 4 | -99, 5 | 45, 6 | 68, 7 | NA, 8 | 72, 9 | 25 10 | ) 11 | 12 | dfs <- nabular(df) 13 | 14 | dfs_are <- are_shade(dfs) 15 | 16 | test_that("are_shade returns the correct values", { 17 | expect_false(dfs_are[["wind"]]) 18 | expect_false(dfs_are[["temp"]]) 19 | expect_true(dfs_are[["wind_NA"]]) 20 | expect_true(dfs_are[["temp_NA"]]) 21 | }) 22 | 23 | test_that("any_shade returns the correct values", { 24 | expect_false(any_shade(df)) 25 | expect_true(any_shade(dfs)) 26 | }) 27 | -------------------------------------------------------------------------------- /tests/testthat/test-shadow-long.R: -------------------------------------------------------------------------------- 1 | ocean_shadow <- nabular(oceanbuoys) 2 | 3 | test_that("shadow_long returns the right dimensions and names etc", { 4 | expect_snapshot( 5 | shadow_long(ocean_shadow) 6 | ) 7 | }) 8 | 9 | test_that("shadow_long works gives the classes with function value transform", { 10 | expect_snapshot( 11 | shadow_long(ocean_shadow, fn_value_transform = as.numeric) 12 | ) 13 | }) 14 | 15 | test_that("shadow_long returns right dimensions, names, etc when filtered", { 16 | expect_snapshot( 17 | shadow_long(ocean_shadow, air_temp_c, humidity) 18 | ) 19 | }) 20 | 21 | test_that("shadow_long returns right dimensions, names, etc when filtered with function value transform", { 22 | expect_snapshot( 23 | shadow_long( 24 | ocean_shadow, 25 | air_temp_c, 26 | humidity, 27 | fn_value_transform = as.numeric 28 | ) 29 | ) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-shadow-shift.R: -------------------------------------------------------------------------------- 1 | miss_vec_5 <- c(10, 10, 9, NA, 3) 2 | miss_vec_2 <- c(4, NA) 3 | miss_vec_3 <- c(4, NA, NA) 4 | miss_vec_4 <- c(4, NA, NA, NA) 5 | 6 | test_that("shadow_shift returns soft deprecation warning", { 7 | rlang::local_options(lifecycle_verbosity = "warning") 8 | expect_snapshot( 9 | shadow_shift(NULL) 10 | ) 11 | expect_snapshot( 12 | error = TRUE, 13 | shadow_shift(3i) 14 | ) 15 | expect_snapshot_warning( 16 | shadow_shift(miss_vec_5) 17 | ) 18 | }) 19 | 20 | test_that("shadow_shift still works", { 21 | rlang::local_options(lifecycle_verbosity = "quiet") 22 | expect_snapshot( 23 | shadow_shift(NULL) 24 | ) 25 | expect_snapshot( 26 | error = TRUE, 27 | shadow_shift(3i) 28 | ) 29 | expect_snapshot( 30 | shadow_shift(miss_vec_5) 31 | ) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-test-any-miss.R: -------------------------------------------------------------------------------- 1 | misses <- c(NA, NA, NA) 2 | complete <- c(1, 2, 3) 3 | mixture <- c(NA, 1, NA) 4 | 5 | test_that("any_na and any_miss returns TRUE when there are all NAs", { 6 | expect_true(any_na(misses)) 7 | expect_true(any_miss(misses)) 8 | }) 9 | 10 | test_that("any_na and any_miss returns TRUE when there are some NAs", { 11 | expect_true(any_na(mixture)) 12 | expect_true(any_miss(mixture)) 13 | }) 14 | 15 | test_that("any_na and any_miss returns FALSE when there only complete values", { 16 | expect_false(any_na(complete)) 17 | expect_false(any_miss(complete)) 18 | }) 19 | 20 | test_that("any_complete returns FALSE when all missing", { 21 | expect_false(any_complete(misses)) 22 | }) 23 | 24 | test_that("any_complete returns TRUE when some missing", { 25 | expect_true(any_complete(mixture)) 26 | }) 27 | 28 | test_that("any_complete returns TRUE when only complete", { 29 | expect_true(any_complete(complete)) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-unbind.R: -------------------------------------------------------------------------------- 1 | df <- data.frame(x = c(NA, 1:4), y = c(NA, NA, 1:3)) 2 | 3 | nab <- nabular(df) 4 | nabu <- unbind_shadow(nab) 5 | 6 | test_that("unbind_shadow returns tibble", { 7 | expect_s3_class(nabu, c("tbl_df")) 8 | }) 9 | 10 | test_that("unbind_shadow returns right dimensions", { 11 | expect_equal(nrow(nabu), nrow(df)) 12 | expect_equal(ncol(nabu), ncol(df)) 13 | }) 14 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/missingness-data-structures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njtierney/naniar/89f2a5df3743df02b6e601d403fa001fc8a79c79/vignettes/missingness-data-structures.png --------------------------------------------------------------------------------