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

bind_table function error when rowbyvar or tablebyvar arguments are used #12

Closed
shengwei66 opened this issue May 30, 2023 · 3 comments
Closed
Assignees

Comments

@shengwei66
Copy link
Collaborator

When creating the AE table of body system by preferred term, an error was encountered by users in the bind_table function call. The reprex code is below:

library(dplyr)
library(tidytlg)

Process data

adae <- cdisc_adae %>%
filter(SAFFL == "Y", TRTEMFL == "Y") %>%
rename(TRT01AN = TRTAN)

adsl <- cdisc_adsl %>%
filter(SAFFL == "Y")

Analysis set row

t1 <- adsl%>%
freq(colvar = 'TRT01AN',
rowvar = 'SAFFL',
rowtext = 'Analysis set: Safety',
statlist = statlist("n"))

Subjects with 1 or more AEs

t2 <- adae %>%
freq(denom_df = adsl,
colvar = 'TRT01AN',
rowvar ='TRTEMFL',
rowtext = 'Subjects with 1 or more AEs',
statlist = statlist("n (x.x%)"),
subset = TRTEMFL == "Y")

create AE header

t3.1 <- data.frame(label = c("System organ class", "Preferred term"),
row_type = "HEADER")

AE System organ class / Preferred term

t3 <- adae %>%
nested_freq(denom_df = adsl,
colvar = 'TRT01AN',
rowvar = 'AEBODSYS*AEDECOD',
subset = TRTEMFL == "Y",
statlist = statlist("n (x.x%)"))

tbl <- bind_table(t1, t2, t3.1, t3,
colvar = "TRT01AN",
rowbyvar = "AEBODSYS")

Error: rowbyvar 'AEBODSYS' does not exist in df 1 or is all NA for function: bind_table

If the rowbyvar argument in the above bind_table call is removed, another error pop up.
tbl <- bind_table(t1, t2, t3.1, t3,
colvar = "TRT01AN")

Error: dfs 3 are missing the required fields for function bind_table

These errors may be due to the check_args implementation.

@elimillera elimillera self-assigned this Jun 9, 2023
@elimillera
Copy link
Collaborator

I'm not sure I see the error. In the bind_table documentation:

... | (required) a set of tidytlg tables to bind together

notes that the tables passed need to be tidytlg tables which t3.1 is not so an error would be expected here.

I think the 'row_header' argument is meant to be used in t3. Which works for me.

  t3 <- adae %>%
    nested_freq(denom_df = adsl,
                colvar = 'TRT01AN',
                rowvar = 'AEBODSYS*AEDECOD',
                subset = TRTEMFL == "Y",
                statlist = statlist("n (x.x%)"),
                row_header = c("System organ class/Preferred Term"))

    tbl <- bind_table(t1, t2, t3,
                      colvar = "TRT01AN")

@shengwei66 Can you tell me what the expected result from the table is?

elimillera added a commit that referenced this issue Jun 12, 2023
@shengwei66
Copy link
Collaborator Author

@elimillera the row_header argument was not working properly in previous version of nested_freq, and that's why t3.1 was created. If we don't use rowbyvar = 'AEBODSYS' in the bind_table call, the column of 'AEBODSYS' will be present in the tbl, which will then need to be manually removed before passing tbl to gentlg. So error is produced when rowbyvar = 'AEBODSYS' is included in the bind_table call:

tbl <- bind_table(t1, t2, t3,
colvar = "TRT01AN",
rowbyvar = "AEBODSYS")
Error: rowbyvar 'AEBODSYS' does not exist in df 1 or is all NA for function: bind_table

The expected tbl should have AEBODSYS removed after bind_table call.

@elimillera
Copy link
Collaborator

The error makes sense to me. bind_table is trying to bind a column that hasn't been provided in all of the tables. Is the idea we don't need to have rowbyvars for all tables binded togehter? The below works for me as well:

library(dplyr)
devtools::load_all()

adae <- cdisc_adae %>%
  filter(SAFFL == "Y", TRTEMFL == "Y") %>%
  rename(TRT01AN = TRTAN)

adsl <- cdisc_adsl %>%
  filter(SAFFL == "Y")

t1 <- adsl%>%
  freq(colvar = 'TRT01AN',
       rowvar = 'SAFFL',
       rowtext = 'Analysis set: Safety',
       statlist = statlist("n")) %>%
  mutate(AEBODSYS = "")

t2 <- adae %>%
  freq(denom_df = adsl,
       colvar = 'TRT01AN',
       rowvar ='TRTEMFL',
       rowtext = 'Subjects with 1 or more AEs',
       statlist = statlist("n (x.x%)"),
       subset = TRTEMFL == "Y") %>%
  mutate(AEBODSYS = "")

t3 <- adae %>%
  nested_freq(denom_df = adsl,
              colvar = 'TRT01AN',
              rowvar = 'AEBODSYS*AEDECOD',
              subset = TRTEMFL == "Y",
              statlist = statlist("n (x.x%)"))

tbl <- bind_table(t1, t2, t3,
                  colvar = "TRT01AN",
                  rowbyvar = "AEBODSYS")

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