Skip to content

Commit 7a5f881

Browse files
Report errors on the table creation to the user (#982)
# Pull Request <!--- Replace `#nnn` with your issue link for reference. --> Fixes #980 Errors are shown to the user: <img width="881" height="480" alt="image" src="https://github.com/user-attachments/assets/258a07f5-6234-45c0-b063-15cf3dfaa2ad" /> Previously no information was provided <details> <summary>Details</summary> ```r data <- within(teal.data::teal_data(), { ADSL <- teal.data::rADSL }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_gtsummary( by = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( choices = c("SEX", "COUNTRY", "SITEID", "ACTARM"), selected = "SEX", multiple = FALSE ) ), include = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( choices = c("SITEID", "COUNTRY", "ACTARM"), selected = "SITEID", multiple = TRUE, fixed = FALSE ) ), type = everything() ~ "continuous2" ) ) ) |> runApp() ``` </details> --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c72a145 commit 7a5f881

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

R/tm_a_regression.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ tm_a_regression <- function(label = "Regression Analysis",
230230
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
231231
checkmate::assert_choice(default_plot_type, seq.int(1L, length(plot_choices)))
232232
checkmate::assert_string(default_outlier_label)
233-
checkmate::assert_list(decorators, "teal_transform_module")
233+
assert_decorators(decorators)
234234

235235
if (length(label_segment_threshold) == 1) {
236236
checkmate::assert_numeric(label_segment_threshold, any.missing = FALSE, finite = TRUE)

R/tm_gtsummary.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ srv_gtsummary <- function(id,
230230
if (length(include_variables)) {
231231
tbl_summary_args$include <- include_variables
232232
}
233-
tbl_summary_args <- c(tbl_summary_args,
234-
nonmissing = input$nonmissing,
235-
percent = input$percent
236-
)
233+
tbl_summary_args$nonmissing <- input$nonmissing
234+
tbl_summary_args$percent <- input$percent
237235
as.call(
238236
c(
239237
list(
@@ -254,9 +252,7 @@ srv_gtsummary <- function(id,
254252
},
255253
table_crane = table_call
256254
)
257-
if (inherits(qq, "qenv.error")) {
258-
validate(as.character(qq))
259-
}
255+
validate_qenv(qq)
260256
qq
261257
})
262258

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,13 @@ set_chunk_dims <- function(pws, q_r, inner_classes = NULL) {
361361
q
362362
})
363363
}
364+
365+
366+
validate_qenv <- function(qenv) {
367+
validate(
368+
need(
369+
inherits(qenv, "qenv"),
370+
sub("when evaluating qenv", "when evaluating", qenv$message, fixed = TRUE)
371+
)
372+
)
373+
}

tests/testthat/test-tm_gtsummary.R

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ testthat::describe("tm_gtsummary module server behavior", {
249249
"by-dataset_test_data_singleextract-select" = "am",
250250
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
251251
)
252+
session$flushReact()
252253

253-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
254+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
254255
testthat::expect_true(inherits(table_r(), "gtsummary"))
255256
}
256257
)
@@ -277,8 +278,9 @@ testthat::describe("tm_gtsummary module server behavior", {
277278
"by-dataset_test_data_singleextract-select" = "am",
278279
"include-dataset_test_data_singleextract-select" = NULL
279280
)
281+
session$flushReact()
280282

281-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
283+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
282284
testthat::expect_true(inherits(table_r(), "gtsummary"))
283285
testthat::expect_gt(length(unique(table_r()$table_body$variable)), 3L)
284286
}
@@ -308,7 +310,9 @@ testthat::describe("tm_gtsummary module server behavior", {
308310
"by-dataset_test_data_singleextract-select" = "am",
309311
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
310312
)
311-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
313+
session$flushReact()
314+
315+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
312316
table <- table_r()
313317
testthat::expect_equal(table$inputs$label, col_label)
314318
testthat::expect_true(all(table$table_body$var_label %in% unlist(col_label)))
@@ -343,7 +347,7 @@ testthat::describe("tm_gtsummary module server behavior with decorators", {
343347
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
344348
)
345349
session$flushReact()
346-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
350+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
347351
testthat::expect_s3_class(table_r(), "gtsummary")
348352
}
349353
)
@@ -379,9 +383,10 @@ testthat::describe("tm_gtsummary module server behavior with decorators", {
379383
"by-dataset_test_data_singleextract-select" = "am",
380384
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
381385
)
382-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
383-
testthat::expect_true(grepl("table2 <-", get_code(print_output_decorated()), fixed = TRUE))
384-
testthat::expect_s3_class(print_output_decorated()$table2, "gtsummary")
386+
387+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
388+
testthat::expect_true(grepl("table2 <-", get_code(session$returned()), fixed = TRUE))
389+
testthat::expect_s3_class(session$returned()$table2, "gtsummary")
385390
}
386391
)
387392
})

tests/testthat/test-utils.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ testthat::describe("Module with decorators:", {
134134
"by-dataset_test_data_singleextract-select" = "am",
135135
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
136136
)
137-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
137+
session$flushReact()
138+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
138139
}
139140
)
140141
})
@@ -168,7 +169,8 @@ testthat::describe("Module with decorators:", {
168169
"by-dataset_test_data_singleextract-select" = "am",
169170
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
170171
)
171-
testthat::expect_is(tryCatch(print_output_decorated(), error = function(e) e), "shiny.silent.error")
172+
session$flushReact()
173+
testthat::expect_is(tryCatch(session$returned(), error = function(e) e), "shiny.silent.error")
172174
}
173175
)
174176
})
@@ -195,7 +197,8 @@ testthat::describe("Module with decorators:", {
195197
"by-dataset_test_data_singleextract-select" = "am",
196198
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
197199
)
198-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
200+
session$flushReact()
201+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
199202
}
200203
)
201204
})
@@ -225,7 +228,8 @@ testthat::describe("Module with decorators:", {
225228
"by-dataset_test_data_singleextract-select" = "am",
226229
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
227230
)
228-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
231+
session$flushReact()
232+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
229233
}
230234
)
231235
})
@@ -254,7 +258,8 @@ testthat::describe("Module with decorators:", {
254258
"by-dataset_test_data_singleextract-select" = "am",
255259
"include-dataset_test_data_singleextract-select" = c("carb", "cyl")
256260
)
257-
testthat::expect_true(endsWith(get_code(print_output_decorated()), "table"))
261+
session$flushReact()
262+
testthat::expect_true(endsWith(get_code(session$returned()), "table"))
258263
}
259264
)
260265
})

0 commit comments

Comments
 (0)