Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: count_abnormal_by_worst_grade returns error when there's only 1 unique PARAM #692

Closed
3 tasks done
JiaLiu0001 opened this issue Aug 29, 2022 · 0 comments · Fixed by #693
Closed
3 tasks done
Assignees
Labels
bug Something isn't working sme

Comments

@JiaLiu0001
Copy link
Contributor

What happened?

A bug happened!

  1. count_abnormal_by_worst_grade returns error when there's only 1 unique PARAM. TLGC LBT07 is referred in the following script.
    Error: df[[variables$param]] is not a valid factor, please check the factor levels (no empty strings allowed)

  2. However, if the PARAM contains more than 1 unique param, no error.

library(formatters)
library(stringr)
library(dplyr)
library(tern)
library(scda)
library(forcats)

adsl <- synthetic_cdisc_data("rcd_2022_02_28")$adsl %>%
  df_explicit_na()

adlb <- synthetic_cdisc_data("rcd_2022_02_28")$adlb %>%
  semi_join(adsl, by = "USUBJID") %>%
  select(USUBJID,TRT01A,PARAM,ATOXGR,ANRIND)

# Derive GRADE_DIR and GRADE_ANL to use in layout from ATOXGR
adlb_f <- adlb %>%
  mutate(
    GRADE_DIR = factor(case_when(
      ATOXGR %in% c("-1", "-2", "-3", "-4") ~ "LOW",
      ATOXGR == "0" ~ "ZERO",
      ATOXGR %in% c("1", "2", "3", "4") ~ "HIGH"),
      levels = c("LOW", "ZERO", "HIGH")),
    GRADE_ANL = fct_relevel(
      fct_recode(ATOXGR, `1` = "-1", `2` = "-2", `3` = "-3", `4` = "-4"), c("0", "1", "2", "3", "4")
    )
  ) %>%
  var_relabel(
    GRADE_DIR = "Direction of Abnormality",
    GRADE_ANL = "Analysis Grade"
  )
adlb_f <- adlb_f %>% mutate(PARAM = 'fake')
# Construct analysis map
map <- unique(adlb_f[adlb_f$GRADE_DIR != "ZERO", c("PARAM", "GRADE_DIR", "GRADE_ANL")]) %>% 
  lapply(as.character) %>%
  as.data.frame() %>%
  arrange(PARAM, desc(GRADE_DIR), GRADE_ANL)


lyt <- basic_table() %>%
  split_cols_by("TRT01A") %>%
  add_colcounts() %>%
  split_rows_by(
    "PARAM",
    label_pos = "topleft",
    split_label = 'Laboratory Test'
  ) %>%
  summarize_num_patients(
    var = "USUBJID",
    required = "ATOXGR",
    .stats = "unique_count"
  ) %>%
  split_rows_by(
    "GRADE_DIR",
    label_pos = "topleft",
    # split_label = 'Direction of Abnormality',
    split_label = obj_label(adlb_f$GRADE_DIR),
    split_fun = trim_levels_to_map(map)
  ) %>%
  count_abnormal_by_worst_grade(
    var = "GRADE_ANL",
    variables = list(id = "USUBJID", param  = "PARAM", grade_dir = "GRADE_DIR")
  ) %>%
  append_topleft("    Highest DAIDS Grading")

result <- build_table(
  lyt = lyt,
  df = adlb_f,
  alt_counts_df = adsl
)
result

sessionInfo()

R version 4.0.4 (2021-02-15)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.4 (Ootpa)

Matrix products: default
BLAS:   /usr/lib64/libblas.so.3.8.0
LAPACK: /opt/mango/R/4.0.4/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] forcats_0.5.1  scda_0.1.2     tern_0.7.6     rtables_0.4.1  magrittr_2.0.1 dplyr_1.0.5    stringr_1.4.0 

loaded via a namespace (and not attached):
 [1] pillar_1.6.0        compiler_4.0.4      tools_4.0.4         packrat_0.5.0       digest_0.6.27       checkmate_2.0.0     lifecycle_1.0.0    
 [8] tibble_3.1.1        gtable_0.3.0        lattice_0.20-41     pkgconfig_2.0.3     rlang_0.4.10        Matrix_1.3-2        rstudioapi_0.13    
[15] cli_2.4.0           DBI_1.1.1           generics_0.1.0      vctrs_0.3.7         grid_4.0.4          tidyselect_1.1.0    glue_1.4.2         
[22] R6_2.5.0            fansi_0.4.2         survival_3.2-10     dfoptim_2020.10-1   ggplot2_3.3.3       purrr_0.3.4         tidyr_1.1.3        
[29] scales_1.1.1        backports_1.2.1     ellipsis_0.3.1      htmltools_0.5.1.1   splines_4.0.4       assertthat_0.2.1    colorspace_2.0-0   
[36] numDeriv_2016.8-1.1 utf8_1.2.1          optimx_2020-4.2     stringi_1.5.3       munsell_0.5.0       broom_0.7.6         crayon_1.4.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@JiaLiu0001 JiaLiu0001 added the bug Something isn't working label Aug 29, 2022
@Melkiades Melkiades added the sme label Aug 29, 2022
@edelarua edelarua self-assigned this Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants