Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions R/tm_t_abnormality_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint: object_len

y$table <- substitute(
expr = {
stopifnot("No common arm levels in data, please check input." = nrow(parent) > 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osenan non-outdated code here

Do we need this protection? I'm worried about other consequences in other modules.

It was moved to the module to prevent generic error. This is a minor change to protect against a never ending calculation of rtables

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify. This line is not existing in the code right now, you are asking if it is required. IMO it is not required. I tried to create an example of this scenario to fail but I could not found a case where the app works. Before the app runs the join keys always fails If I filter and keep the parent dataset without rows. It always fails so I expect this protection to be really an edge case that it is not necessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this it risks hanging on forever

Just remove the line and run the example, then select N

image

table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent)
},
env = list(parent = as.name(parentname))
Expand Down Expand Up @@ -522,32 +523,40 @@ srv_t_abnormality_by_worst_grade <- function(id, # nolint: object_length.
anl_q <- merged_adsl_anl$data

validate_checks <- reactive({
input_arm <- anl_selectors$arm_var()$variables$selected
validate(
need(length(input_arm) == 1L, "Please select a treatment variable.")
teal::need_input(
inputId = "arm_var-variables-selected",
condition = length(anl_selectors$arm_var()$variables$selected) == 1L,
message = "Please select a treatment variable."
)
)
validate(
need(
length(anl_selectors$id_var()$variables$selected) >= 1L,
"Please select a Subject Identifier."
teal::need_input(
inputId = "id_var-variables-selected",
condition = length(anl_selectors$id_var()$variables$selected) >= 1L,
message = "Please select a Subject Identifier."
),
need(
length(anl_selectors$atoxgr_var()$variables$selected) >= 1L,
"Please select Analysis Toxicity Grade variable."
teal::need_input(
inputId = "atoxgr_var-variables-selected",
condition = length(anl_selectors$atoxgr_var()$variables$selected) >= 1L,
message = "Please select Analysis Toxicity Grade variable."
),
need(
length(anl_selectors$worst_low_flag_var()$variables$selected) >= 1L,
"Please select the Worst Low Grade flag variable."
teal::need_input(
inputId = "worst_low_flag_var-variables-selected",
condition = length(anl_selectors$worst_low_flag_var()$variables$selected) >= 1L,
message = "Please select the Worst Low Grade flag variable."
),
need(
length(anl_selectors$worst_high_flag_var()$variables$selected) >= 1L,
"Please select the Worst High Grade flag variable."
teal::need_input(
inputId = "worst_high_flag_var-variables-selected",
condition = length(anl_selectors$worst_high_flag_var()$variables$selected) >= 1L,
message = "Please select the Worst High Grade flag variable."
)
)
validate(
need(
!is.null(input$worst_flag_indicator) && nzchar(input$worst_flag_indicator),
"Please select a value indicating the worst grade."
teal::need_input(
inputId = "worst_flag_indicator",
condition = !is.null(input$worst_flag_indicator),
message = "Please select a value indicating the worst grade."
)
)

Expand All @@ -558,9 +567,10 @@ srv_t_abnormality_by_worst_grade <- function(id, # nolint: object_length.
pcd$values$selected
}
validate(
need(
length(pcd_vals) >= 1L,
"Please select at least one Laboratory parameter."
teal::need_input(
inputId = "paramcd-values-selected",
condition = length(pcd_vals) >= 1L,
message = "Please select at least one Laboratory parameter."
)
)

Expand Down Expand Up @@ -647,7 +657,9 @@ srv_t_abnormality_by_worst_grade <- function(id, # nolint: object_length.

obj <- anl_q()
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "### Table")
teal.code::eval_code(obj, as.expression(unlist(my_calls)))
obj <- teal.code::eval_code(obj, as.expression(unlist(my_calls)))
validate(need(!inherits(obj, "qenv.error"), obj$message))
obj
})

decorated_table_q <- teal::srv_transform_teal_data(
Expand Down
8 changes: 6 additions & 2 deletions R/tm_t_summary_by.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ template_summary_by <- function(parentname,
#' by_vars = variables(choices = c("PARAM", "AVISIT"), selected = "AVISIT"),
#' summarize_vars = variables(choices = c("AVAL", "CHG"), selected = "AVAL"),
#' useNA = "ifany",
#' paramcd = variables(choices = "PARAMCD")
#' paramcd = picks(
#' variables(choices = "PARAMCD"),
#' values(selected = "ALT"),
#' check_dataset = FALSE
#' )
#' )
#' )
#' )
Expand Down Expand Up @@ -444,7 +448,7 @@ tm_t_summary_by <- function(label,
summarize_vars <- migrate_choices_selected_to_variables(summarize_vars)
id_var <- migrate_choices_selected_to_variables(id_var)
denominator <- migrate_choices_selected_to_values(denominator)
if (!is.null(paramcd)) paramcd <- migrate_value_choices_to_picks(paramcd, multiple = FALSE)
if (!is.null(paramcd)) paramcd <- migrate_value_choices_to_picks(paramcd, multiple = TRUE)

checkmate::assert_string(label)
checkmate::assert_string(dataname)
Expand Down
10 changes: 7 additions & 3 deletions man/tm_t_summary_by.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/_snaps/tm_t_abnormality_by_worst_grade.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

$table
{
stopifnot(`No common arm levels in data, please check input.` = nrow(adsl) >
0)
table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = adsl)
}

Expand Down Expand Up @@ -88,6 +90,8 @@

$table
{
stopifnot(`No common arm levels in data, please check input.` = nrow(myadsl) >
0)
table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = myadsl)
}

Expand Down
11 changes: 9 additions & 2 deletions tests/testthat/test-tm_t_summary_by.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,16 @@ testthat::describe("template_summary_by rtables output for different statistics"
parentname = "ADSL",
arm_var = teal.picks::variables(choices = "ARM", selected = "ARM", fixed = TRUE),
by_vars = teal.picks::variables(choices = "AVISIT", selected = "AVISIT", fixed = TRUE),
summarize_vars = teal.picks::variables(choices = "AVALC", selected = "AVALC", fixed = TRUE),
summarize_vars = teal.picks::variables(choices = "AVALC", selected = "AVALC", fixed = TRUE, multiple = TRUE),
categorical_stats = "count",
paramcd = teal.picks::variables(choices = "PARAMCD")
paramcd = suppressWarnings(
teal.picks::picks(
teal.picks::variables(choices = "PARAMCD", selected = "PARAMCD"),
teal.picks::values(selected = "ALT", multiple = TRUE),
check_dataset = FALSE
),
classes = "pick_delayed"
)
)

it("adds 'fraction' to the statistics", {
Expand Down
Loading