tern
tern copied to clipboard
Informative error handling for missing values
I've seen new NEST users (myself included) get confused when setting up their first AE by grade teal visualization and getting a not super informative "subscript out of bound" error. Turns out you get this when you have missing values in required variables, e.g. AETOXGR, AEBODSYS, etc. Just wanted to suggest giving the end user a more informative error message for ease of debugging. Thanks!
Provenance:
Creator: harric17
Can you provide code example to reproduce error message?
Provenance:
Creator: junlue
Error message due to missing values in required variables, e.g. AEBODSYS, AEDECOD, etc.:
Tried to evaluate following code:
{ tbl <- t_events_per_term_grade_id(terms = ANL[, c("AEBODSYS", "AEDECOD"), drop = FALSE], id = ANL[["USUBJID"]], grade = ANL[["AETOXGR"]], col_by = as.factor(ANL[["ARM"]]), col_N = table(ADSL_P[["ARM"]]), total = "All Patients") tbl}
Got following error message:
subscript out of bounds
The error is not super informative that the issue is missing values. Another solution might be for NEST to impute missing values with "Unknown" or "Missing" on its own so no error is produced. Here's the code:
<REDACTED>NEST/nest_on_bee/master/bee_nest_utils.R")
bee_use_nest(release = "2020_08_20")
library(teal)
library(teal.modules.general)
library(teal.modules.clinical)
library(SAICE)
initialize_connection()
ADSL <- read_entimice("<path>/adsl.sas7bdat")
ADAE <- read_entimice("<path>/adae.sas7bdat")
close_connection()
ADAE = ADAE %>%
mutate(AETOXGR = as.factor(AETOXGR))
library(random.cdisc.data)
library(dplyr)
app <- teal::init(
data = cdisc_data(
cdisc_dataset("ADSL", ADSL),
cdisc_dataset("ADAE", ADAE),
code = 'ADSL <- radsl(cached = TRUE)
ADAE <- radae(cached = TRUE)',
check = FALSE
),
modules = root_modules(
tm_t_events_by_grade(
label = "AE Table by Grade",
dataname = 'ADAE',
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
llt = choices_selected(
choices = variable_choices(ADAE, c("AETERM", "AEDECOD")),
selected = c("AEDECOD")
),
hlt = choices_selected(
choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")),
selected = "AEBODSYS"
),
grade = choices_selected(
choices = variable_choices(ADAE, c("AETOXGR")),
selected = "AETOXGR"
),
add_total = TRUE
)
)
)
shinyApp(app$ui, app$server)
Provenance:
Creator: harric17