insightsengineering / cards

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

Add unit tests for non-syntactic column names #170

Closed ddsjoberg closed 4 months ago

ddsjoberg commented 5 months ago

At first look, it seems they work well. But should do some more testing and add unit tests so we don't accidentally break it in the future.

library(cards)

ADSL |> 
  dplyr::mutate(`Age Group` = AGEGR1) |> 
  ard_categorical(variables = `Age Group`) |> 
  head(2)
#> {cards} data frame: 2 x 9
#>    variable variable_level   context stat_name stat_label statistic
#> 1 Age Group            <65 categori…         n          n        33
#> 2 Age Group            <65 categori…         N          N       254
#> ℹ 3 more variables: statistic_fmt_fn, warning, error

ADSL |> 
  dplyr::mutate(`Age Group` = AGEGR1) |> 
  ard_categorical(variables = "Age Group") |> 
  head(2)
#> {cards} data frame: 2 x 9
#>    variable variable_level   context stat_name stat_label statistic
#> 1 Age Group            <65 categori…         n          n        33
#> 2 Age Group            <65 categori…         N          N       254
#> ℹ 3 more variables: statistic_fmt_fn, warning, error

ADSL |> 
  dplyr::mutate(`Patient Age` = AGE) |> 
  ard_continuous(variables = `Patient Age`) |> 
  head(2)
#> {cards} data frame: 2 x 8
#>      variable   context stat_name stat_label statistic statistic_fmt_fn
#> 1 Patient Age continuo…         N          N       254                0
#> 2 Patient Age continuo…      mean       Mean    75.087                1
#> ℹ 2 more variables: warning, error

ADSL |> 
  dplyr::mutate(`Patient Age` = AGEGR1) |> 
  ard_continuous(variables = "Patient Age") |> 
  head(2)
#> {cards} data frame: 2 x 8
#>      variable   context stat_name stat_label statistic   warning
#> 1 Patient Age continuo…         N          N       254          
#> 2 Patient Age continuo…      mean       Mean        NA argument…
#> ℹ 2 more variables: statistic_fmt_fn, error

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