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

split_cols_by() does wrong ordering if labels_var is a factor and not a character #173

Closed
danielinteractive opened this issue Mar 11, 2021 · 2 comments
Assignees
Labels

Comments

@danielinteractive
Copy link
Contributor

In the below example we have a labels variable (which does not have the same alphabetic ordering as the original arm variable). This gives the wrong labeling of the columns when it is a factor. Only when it is character it works as expected. I would guess that fixing this should be simply putting as.character() in the right place?

library(rtables)
library(dplyr)

ex_adsl <- ex_adsl %>%
  mutate(
    ARMLAB = factor(case_when( # need to omit factor to solve problem below
      ARM == "A: Drug X" ~ "Drug X",
      ARM == "B: Placebo" ~ "Placebo",
      ARM == "C: Combination" ~ "Combination")
  ))

lyt_orig <- basic_table() %>%
  split_cols_by("ARM") %>%
  analyze(c("AGE", "BMRKR2"))
tbl_orig <- build_table(lyt_orig, ex_adsl)

lyt_lab <- basic_table() %>%
  split_cols_by("ARM", labels_var = "ARMLAB") %>%
  analyze(c("AGE", "BMRKR2"))
tbl_lab <- build_table(lyt_lab, ex_adsl)

tbl_orig
tbl_lab # wrong labeling here

Session info:

R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so

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

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

other attached packages:
[1] dplyr_1.0.0   rtables_0.3.6 magrittr_1.5 

loaded via a namespace (and not attached):
 [1] fansi_0.4.1       assertthat_0.2.1  packrat_0.5.0     digest_0.6.25     crayon_1.3.4     
 [6] R6_2.4.1          lifecycle_0.2.0   pillar_1.4.3      cli_2.2.0         rlang_0.4.9      
[11] rstudioapi_0.11   vctrs_0.3.1       generics_0.0.2    ellipsis_0.3.0    tools_3.6.3      
[16] glue_1.4.0        purrr_0.3.4       compiler_3.6.3    pkgconfig_2.0.3   htmltools_0.5.1.1
[21] tidyselect_1.1.0  tibble_3.0.1 
@danielinteractive
Copy link
Contributor Author

@anajens fyi

@gmbecker
Copy link
Collaborator

Typo in the commit message but this is fixed in 39c655e and pushed as a narrow bugfix to devel. The regression test will be added to the branch I'm currently working on for now (mostly cause I forgot to add it to the commit that got pushed directly to devel).

Feb - April 2021 automation moved this from ToDO to Done Mar 12, 2021
gmbecker added a commit that referenced this issue Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

2 participants