insightsengineering / cards

CDISC Analysis Results Data
https://insightsengineering.github.io/cards/
30 stars 2 forks source link

Improve error messaging with `ard_categorical()` when counting not possible #167

Closed ddsjoberg closed 7 months ago

ddsjoberg commented 7 months ago

If we have a character vector of all NA, there is nothing to tabulate and the error messaging is not helpful. I suppose this would happen for any NA vector except for factors and logicals since those two cases we know what the levels should be.

tibble::tibble(
  # all_na_fct = factor(rep_len(NA, 10), levels = c("Yes", "No"))
  # all_na_lgl = rep_len(NA, 10),
  all_na_chr = rep_len(NA_character_, 10)
) |> 
  cards::ard_categorical(
    variables = all_na_chr
  )
#> Error in names(df) <- repaired_names(c(names2(dimnames(x)), n), repair_hint = TRUE, : 'names' attribute [2] must be the same length as the vector [1]

Created on 2024-02-09 with reprex v2.1.0