pharmaverse/tidytlg

denom_df in table metadata doesn't turn into data frame in batch run

Closed this issue · 0 comments

This issue is about the error message of 'The supplied argument denom_df of function freq is of type character but must be of type data.frame' when using table metadata approach in batch run.

The reprex code in below:

adsl <- cdisc_adsl
adae <- cdisc_adae %>%
rename(TRT01PN = TRTAN)

table_metadata <- tibble::tribble(
~anbr,~func, ~df, ~rowvar, ~rowtext, ~statlist, ~subset, ~denom_df,
1, "freq", "adae", "TRTEMFL", "Subjects with 1 or more AEs", statlist(c("n (x.x%)")), "TRTEMFL == 'Y'", "adsl") %>%
mutate(colvar = "TRT01PN")

tbl <- generate_results(table_metadata,
column_metadata_file = system.file("extdata/column_metadata.xlsx", package = "tidytlg"),
tbltype = "type1")

This code runs fine interactively, but will produce the above error message in the batch run. The issue is coming from the do_tidytlg function inside generate_results, where there is a conditional check about denom_df:

if (!is.null(x$denom_df) && exists(x$denom_df))
x$denom_df <- get(x$denom_df, envir = env) %>%
tlgsetup(var = x$colvar,
column_metadata = column_metadata,
column_metadata_file = column_metadata_file,
tbltype = tbltype)

The function call of exists(x$denom_df) would evaluate to FALSE in batch run, and so the get function will not run to turn the character of denom_df into data.frame. To fix this issue, the envir = env needs to be included in the exists function call.