Skip to content

Bug Report: when using a factor column with rename_ard_columns() the values are getting coerced to integers #542

@alanahjonas95

Description

@alanahjonas95

What happened?

factor column here race, when rename_ard_columns() is called the values are coereced to integers and we loose the
character race values.

adsl_ <- cards::ADSL |>
  dplyr::mutate(RACE = factor(RACE))

res <- cards::ard_categorical(
  data = adsl_,
  by = TRT01A,
  variables = c(RACE, ETHNIC)
) |>
  cards::rename_ard_columns()

res
#> # A tibble: 45 × 10
#>    TRT01A  RACE ETHNIC context stat_name stat_label stat  fmt_fun warning error 
#>    <chr>  <int> <chr>  <chr>   <chr>     <chr>      <lis> <list>  <list>  <list>
#>  1 Place…     1 <NA>   catego… n         n          <int> <int>   <NULL>  <NULL>
#>  2 Place…     1 <NA>   catego… N         N          <int> <int>   <NULL>  <NULL>
#>  3 Place…     1 <NA>   catego… p         %          <dbl> <fn>    <NULL>  <NULL>
#>  4 Place…     2 <NA>   catego… n         n          <int> <int>   <NULL>  <NULL>
#>  5 Place…     2 <NA>   catego… N         N          <int> <int>   <NULL>  <NULL>
#>  6 Place…     2 <NA>   catego… p         %          <dbl> <fn>    <NULL>  <NULL>
#>  7 Place…     3 <NA>   catego… n         n          <int> <int>   <NULL>  <NULL>
#>  8 Place…     3 <NA>   catego… N         N          <int> <int>   <NULL>  <NULL>
#>  9 Place…     3 <NA>   catego… p         %          <dbl> <fn>    <NULL>  <NULL>
#> 10 Place…    NA HISPA… catego… n         n          <int> <int>   <NULL>  <NULL>
#> # ℹ 35 more rows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions