Skip to content

A bug of prepare_boxly #45

Description

@LittleBeannie

The following code works.

adsl <- r2rtf::r2rtf_adsl |> 
  filter(TRT01P %in% c("Placebo", "Xanomeline High Dose")) |>
  mutate(TRT01P = factor(TRT01P,
                         levels = c("Placebo", "Xanomeline High Dose"),
                         labels = c("Control", "Experimental")),
         TRT01A = factor(TRT01A,
                         levels = c("Placebo", "Xanomeline High Dose"),
                         labels = c("Control", "Experimental")),
         RACE = stringr::str_to_sentence(RACE))

adlb <- boxly_adlb |> 
  filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |>
  mutate(TRTA = factor(TRTA,
                       levels = c("Placebo", "Xanomeline High Dose"),
                       labels = c("Control", "Experimental"))) |>
  rename(TRT01A = TRTA)

meta_lab <- meta_adam(population = adsl,
                      observation = adlb) |>
  define_plan(plan = plan(analysis = "lab_boxplot",
                          population = "apat",
                          observation = "wk12",
                          parameter = "alp;alt;bili;sodium;urate")) |>
  define_population(name = "apat",
                    group = "TRT01A",
                    subset = SAFFL == "Y",
                    label = "APaT Population") |>
  define_observation(name = "wk12",
                     group = "TRT01A",
                     var = "PARAM",
                     subset = SAFFL == "Y",
                     label = "") |>
  define_analysis(name = "lab_boxplot",
                  label = "Interactive Box Plot",
                  x = "AVISITN", 
                  y = "CHG") |>
  define_parameter(name = "alp",
                   label = "Alanine Aminotransferase (U/L)",
                   subset = PARAM == "Alanine Aminotransferase (U/L)") |>
  define_parameter(name = "alt",
                   label = "Alkaline Phosphatase (U/L)",
                   subset = PARAM == "Alkaline Phosphatase (U/L)") |>
  define_parameter(name = "bili",
                   label = "Bilirubin (umol/L)",
                   subset = PARAM == "Bilirubin (umol/L)") |>
  define_parameter(name = "sodium",
                   label = "Sodium (mmol/L)",
                   subset = PARAM == "Sodium (mmol/L)") |>
  define_parameter(name = "urate",
                   label = "Urate (umol/L)",
                   subset = PARAM == "Urate (umol/L)") |>
  meta_build()

meta_lab |>
  prepare_boxly(population = "apat",
                observation = "apat",
                analysis = "lab_boxplot") |>
  boxly()

> metalite::collect_adam_mapping(meta_lab, "wk12")$var
[1] "PARAM"

However, if I change the observation to "apat", then it breaks!

meta_lab <- meta_adam(population = adsl,
                      observation = adlb) |>
  define_plan(plan = plan(analysis = "lab_boxplot",
                          population = "apat",
                          observation = "apat",
                          parameter = "alp;alt;bili;sodium;urate")) |>
  define_population(name = "apat",
                    group = "TRT01A",
                    subset = SAFFL == "Y",
                    label = "APaT Population") |>
  define_observation(name = "apat",
                     group = "TRT01A",
                     var = "PARAM",
                     subset = SAFFL == "Y",
                     label = "APaT Population") |>
  define_analysis(name = "lab_boxplot",
                  label = "Interactive Box Plot",
                  x = "AVISITN", 
                  y = "CHG") |>
  define_parameter(name = "alp",
                   label = "Alanine Aminotransferase (U/L)",
                   subset = PARAM == "Alanine Aminotransferase (U/L)") |>
  define_parameter(name = "alt",
                   label = "Alkaline Phosphatase (U/L)",
                   subset = PARAM == "Alkaline Phosphatase (U/L)") |>
  define_parameter(name = "bili",
                   label = "Bilirubin (umol/L)",
                   subset = PARAM == "Bilirubin (umol/L)") |>
  define_parameter(name = "sodium",
                   label = "Sodium (mmol/L)",
                   subset = PARAM == "Sodium (mmol/L)") |>
  define_parameter(name = "urate",
                   label = "Urate (umol/L)",
                   subset = PARAM == "Urate (umol/L)") |>
  meta_build()

> metalite::collect_adam_mapping(meta_lab, "apat")$var
NULL

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions