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

the column names (cols 2, 5, 6) appear in the wrong order (contents of columns are in the correct places) #8

Closed
shajoezhu opened this issue Aug 12, 2022 · 3 comments

Comments

@shajoezhu
Copy link
Collaborator

Table design from DSL01 design template.
Formatting changes applied to initial design.

@shajoezhu when this listing is created, the column names (cols 2, 5, 6) appear in the wrong order (contents of columns are in the correct places).

Listing Code:

library(scda)
library(dplyr)
library(rlistings)

adsl <- synthetic_cdisc_data("rcd_2022_06_27")$adsl

out <- adsl %>%
  filter(AEWITHFL == 'Y') %>%
  mutate(ID = paste(SITEID, SUBJID, sep = "/"),
         ASR = paste(AGE, SEX, RACE, sep = "/"),
         DISCONT = ifelse(!is.na(DCSREAS) & EOSSTT != 'COMPLETED', "Yes", 'No'),
         SSADM = as.POSIXct(
           strftime(TRTSDTM, format = "%Y-%m-%d %H:%M:%S"),
           format = "%Y-%m-%d",
           tz = "UTC")
  ) %>%
  select(ID, ASR, TRT01A, SSADM, EOSDY, DISCONT)

var_labels(out) <- c(
  ID = "Center/Patient ID",
  ASR = "Age/Sex/Race",
  DISCONT = "Discontinued Early from Study?",
  SSADM = "Date of First Study Drug Administration",
  TRT01A = "Treatment",
  EOSDY = "Study Day of Withdrawal"
)

lsting <- as_listing(
  out,
  cols = names(out)
)

head(lsting, n = 10)

Output Listing:

Center/Patient ID            Age/Sex/Race            Discontinued Early from Study?   Date of First Study Drug Administration   Treatment   Study Day of Withdrawal
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
BRA-1/id-42         36/M/BLACK OR AFRICAN AMERICAN             A: Drug X                            2020-01-01                     NA                 No           
BRA-11/id-237                 64/F/ASIAN                     C: Combination                         2020-03-10                     731                No           
CHN-1/id-26                   29/M/WHITE                       A: Drug X                            2020-07-16                     731                No           
CHN-1/id-62                   36/F/WHITE                       A: Drug X                            2020-11-22                     90                 Yes          
CHN-11/id-256                 23/M/ASIAN                       A: Drug X                            2020-03-17                     731                No           
CHN-11/id-257                 32/F/ASIAN                     C: Combination                         2020-11-15                     731                No           
CHN-11/id-263                 34/F/ASIAN                     C: Combination                         2019-04-03                     731                No           
CHN-11/id-349                 40/M/ASIAN                     C: Combination                         2020-11-13                     731                No           
CHN-11/id-91        44/M/BLACK OR AFRICAN AMERICAN           C: Combination                         2020-05-29                     260                Yes          
CHN-13/id-102                 37/M/ASIAN                       B: Placebo                           2019-03-23                     731                No           

Originally posted by @edelarua in https://github.com/insightsengineering/sme-tasks/issues/327#issuecomment-1203158410

@gmbecker
Copy link
Contributor

The issue is actually not with rlistings per se (though there were other problems I had to fix to run this code, so I'm not really sure how you were doing it, I suspect you have an (possibly very) out of date copy of formatters installed wherever you were trying this.

That said, the issue is actually that var_labels<- is purely positional, and you're giving the labels in an order other than the one the columns appear in.

So rlistings is actually doing the fully correct thing, using the column labels formatters incorrectly placed. I will fix this in formatters.

@shajoezhu
Copy link
Collaborator Author

I see! Thanks for the explanation. I understand, I was wondering which way do you think is a sensible work flow

  1. sort the column order, then call the var_labels setter, or
  2. call the var_labels setter, and sort the column order

@gmbecker
Copy link
Contributor

gmbecker commented Aug 16, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants