Browse Source

Soft-deprecate conditional formulas

Show a warning if detecting such formula but still use it
tags/0.2.0^2
Maxime Wack 2 years ago
parent
commit
7dbfe60974
2 changed files with 9 additions and 5 deletions
  1. +5
    -0
      R/build.R
  2. +4
    -5
      R/stats.R

+ 5
- 0
R/build.R View File

@@ -13,6 +13,11 @@ statColumn <- function(stat, data) {
# Apply one statified stat function to every variable in the data
# Return a simple vector for the column
# Statify checks types and output for the stat function. Returns a numeric vector or a character vector if needed.
if (length(stat) == 3)
warning("Conditional formulas are deprecated and will be removed in 1.0.0
purrr::map style formulas are used now.
For example, `is.normal ~ mean | median` becomes `~ if (is.normal(.)) mean(.) else median(.)`")

data %>%
lapply(statify, stat) %>%
unlist()


+ 4
- 5
R/stats.R View File

@@ -18,11 +18,10 @@ statify <- function(x, f) {
x <- stats::na.omit(x)

## Deprecate conditional formula
if (length(f) > 2)
stop("Conditional formulas are deprecated. Replace `~ {cond} | {if_T} | {if_F}` with `~ if({cond}) {if_T} then {if_F}`")

# Use rlang to parse function or formula (as in map, etc.)
f <- rlang::as_function(f)
if (length(f) == 3)
f <- parse_formula(x, f)
else
f <- rlang::as_function(f)

# Try f(x), silent warnings and fail with NA
res <- tryCatch(f(x),


Loading…
Cancel
Save