When a statistical summary function errors, the "stat" column will be NULL. It is, however, sometimes useful to replace these values with a non-NULL value, e.g. NA.

replace_null_statistic(x, value = NA, rows = TRUE)

Arguments

x

(data.frame)
an ARD data frame of class 'card'

value

(usually a scalar)
The value to replace NULL values with. Default is NA.

rows

(data-masking)
Expression that return a logical value, and are defined in terms of the variables in .data. Only rows for which the condition evaluates to TRUE are replaced. Default is TRUE, which applies to all rows.

Value

an ARD data frame of class 'card'

Examples

# the quantile functions error because the input is character, while the median function returns NA
data.frame(x = rep_len(NA_character_, 10)) |>
  ard_summary(
    variables = x,
    statistic = ~ continuous_summary_fns(c("median", "p25", "p75"))
  ) |>
  replace_null_statistic(rows = !is.null(error))
#> # An ARD data frame: 3 × 8
#>   variable context stat_name stat   error                                  
#>   <chr>    <chr>   <chr>     <list> <list>                                 
#> 1 x        summary median    NA     <NULL>                                 
#> 2 x        summary p25       NA     non-numeric argument to binary operator
#> 3 x        summary p75       NA     non-numeric argument to binary operator
#> # ℹ 3 more variables: stat_label <chr>, fmt_fun <list>, warning <list>