Skip to content

R package tidyna provides drop-in replacements for common R functions that default to 'na.rm = TRUE'

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

statzhero/tidyna

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tidyna

Tired of littering your code with na.rm = TRUE? tidyna masks common R functions and warns you when NAs are removed. It handles some special cases. The table() default is set to useNA = "ifany".

Installation

Install from CRAN:

install.packages("tidyna")

Or install the development version from GitHub:

# install.packages("pak")
pak::pak("statzhero/tidyna")

Usage

library(tidyna)

x <- c(1, 2, NA)
mean(x)
#> ⚠️ 1 missing value removed.
#> [1] 1.5

Suppress warnings with options(tidyna.warn = FALSE).

Functions

  • Summary: mean, sum, prod, sd, var, median, quantile
  • Extrema: min, max, range, pmax, pmin
  • Logical: any, all
  • Row-wise: rowSums, rowMeans
  • Correlation: cor
  • Table: table

Special cases

All-NA input throws error: When all values are NA, tidyna throws an error instead of returning misleading values like Inf, NaN, or 0:

sum(c(NA, NA))
#> Error: All values are NA; check if something went wrong.

base::sum(c(NA, NA), na.rm = TRUE)
#> [1] 0

rowSums returns NA for all-NA rows, but errors if the entire matrix is NA.

pmax/pmin return NA for positions where all inputs are NA (with a warning), but error if every position is all-NA:

pmax(c(NA, 1), c(NA, 2))
#> ⚠️ 1 position had all NA values.
#> [1] NA  2

pmax(c(NA, NA), c(NA, NA))
#> Error: All values are NA; check if something went wrong.

cor defaults to use = "pairwise.complete.obs" instead of erroring on NAs.

table defaults to useNA = "ifany", showing NA counts when present rather than silently dropping them.

Roadmap

  • Add explicit _aware suffixed versions (mean_aware, sum_aware, etc.) for users who prefer not to mask base functions.

Related packages

  • naflex: Conditional NA removal based on thresholds
  • na.tools: Utilities for working with missing values

About

R package tidyna provides drop-in replacements for common R functions that default to 'na.rm = TRUE'

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages