Skip to content

Commit e732a33

Browse files
Address issues related to testing with shinytest2 the examples (#1423)
# Pull Request Attempts to fix insightsengineering/coredev-tasks#536 on this package. 1. system.file don't raise an error (but I need to check if it is empty or it reports useful info). 2. When there is an error on a shiny session the test of the example fails. 3. Many modules missed some package prefix or loaded (modules failed). 4. Stop using `load_all` inside test-examples. 5. Checks all examples due to upstream issues being fixed since last year. For testing 2 create a new file and add a new file and document to add this example: ``` #' Example failing #' @export #' @examples #' app <- init( #' data = teal_data( #' new_iris = transform(iris, id = seq_len(nrow(iris))), #' new_mtcars = transform(mtcars, id = seq_len(nrow(mtcars))) #' ), #' modules = modules( #' module( #' "Iris Sepal.Length histogram", #' server = function(input, output, session, data) { #' stop("yada") # 🔍 this will fail the app #' }, #' ui = function(id, ...) { #' ns <- NS(id) #' plotOutput(ns("hist")) #' }, #' datanames = "new_iris" #' ) #' ) #' ) #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } module_error <- function() {} ``` Then for all check with `R CMD check` or `devtools::test(filter = "examples")` from plain R session. ------- Rstudio reports an error on some examples: ``` Error in .Call("rs_enqueClientEvent", type, data, PACKAGE = "(embedding)") : "rs_enqueClientEvent" not available for .Call() for package "(embedding)" ``` --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 93f7d91 commit e732a33

38 files changed

+156
-121
lines changed

R/tm_a_gee.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ template_a_gee <- function(output_table,
165165
#' {{ next_example }}
166166
#'
167167
#' @examples
168-
#' library(dplyr)
169168
#'
170169
#' data <- teal_data()
171170
#' data <- within(data, {
171+
#' library(teal.modules.clinical)
172+
#' library(dplyr)
172173
#' ADSL <- tmc_ex_adsl
173174
#' ADQS <- tmc_ex_adqs %>%
174175
#' filter(ABLFL != "Y" & ABLFL2 != "Y") %>%

R/tm_a_mmrm.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ template_mmrm_plots <- function(fit_name,
499499
#' {{ next_example }}
500500
#'
501501
#' @examples
502-
#' library(dplyr)
503502
#'
504503
#' arm_ref_comp <- list(
505504
#' ARMCD = list(
@@ -510,6 +509,8 @@ template_mmrm_plots <- function(fit_name,
510509
#'
511510
#' data <- teal_data()
512511
#' data <- within(data, {
512+
#' library(teal.modules.clinical)
513+
#' library(dplyr)
513514
#' ADSL <- tmc_ex_adsl
514515
#' ADQS <- tmc_ex_adqs %>%
515516
#' filter(ABLFL != "Y" & ABLFL2 != "Y") %>%

R/tm_g_barchart_simple.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
#'
4848
#' @examples
4949
#' library(nestcolor)
50-
#' library(dplyr)
5150
#'
5251
#' data <- teal_data()
5352
#' data <- within(data, {
53+
#' library(teal.modules.clinical)
54+
#' library(formatters)
55+
#' library(dplyr)
5456
#' ADSL <- tmc_ex_adsl %>%
5557
#' mutate(ITTFL = factor("Y") %>%
5658
#' with_label("Intent-To-Treat Population Flag"))

R/tm_g_ci.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ template_g_ci <- function(dataname,
223223
#'
224224
#' data <- teal_data()
225225
#' data <- within(data, {
226+
#' library(teal.modules.clinical)
227+
#' library(dplyr)
226228
#' ADSL <- tmc_ex_adsl
227229
#' ADLB <- tmc_ex_adlb
228230
#' })
@@ -454,8 +456,7 @@ srv_g_ci <- function(id,
454456
)
455457

456458
anl_q <- reactive({
457-
data() %>%
458-
teal.code::eval_code(as.expression(anl_inputs()$expr))
459+
teal.code::eval_code(data(), as.expression(anl_inputs()$expr))
459460
})
460461

461462
all_q <- reactive({

R/tm_g_forest_rsp.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ template_forest_rsp <- function(dataname = "ANL",
267267
#'
268268
#' @examples
269269
#' library(nestcolor)
270-
#' library(dplyr)
271270
#'
272271
#' data <- teal_data()
273272
#' data <- within(data, {
273+
#' library(teal.modules.clinical)
274+
#' library(formatters)
275+
#' library(dplyr)
274276
#' ADSL <- tmc_ex_adsl
275277
#' ADRS <- tmc_ex_adrs %>%
276278
#' mutate(AVALC = d_onco_rsp_label(AVALC) %>%

R/tm_g_forest_tte.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ template_forest_tte <- function(dataname = "ANL",
268268
#'
269269
#' @examples
270270
#' library(nestcolor)
271-
#' library(dplyr)
272271
#'
273272
#' data <- teal_data()
274273
#' data <- within(data, {
274+
#' library(teal.modules.clinical)
275+
#' library(formatters)
276+
#' library(dplyr)
275277
#' ADSL <- tmc_ex_adsl
276278
#' ADTTE <- tmc_ex_adtte
277279
#' ADSL$RACE <- droplevels(ADSL$RACE) %>% with_label("Race")

R/tm_g_ipp.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ template_g_ipp <- function(dataname = "ANL",
4141
ggplot2_args = teal.widgets::ggplot2_args(),
4242
suppress_legend = FALSE,
4343
add_avalu = TRUE) {
44-
4544
checkmate::assert_string(dataname)
4645
checkmate::assert_string(paramcd)
4746
checkmate::assert_string(arm_var)
@@ -204,17 +203,18 @@ template_g_ipp <- function(dataname = "ANL",
204203
#'
205204
#' @examples
206205
#' library(nestcolor)
207-
#' library(dplyr)
208206
#'
209207
#' data <- teal_data()
210208
#' data <- within(data, {
209+
#' library(teal.modules.clinical)
210+
#' library(tern)
211211
#' library(dplyr)
212212
#' ADSL <- tmc_ex_adsl %>%
213213
#' slice(1:20) %>%
214-
#' tern::df_explicit_na()
214+
#' df_explicit_na()
215215
#' ADLB <- tmc_ex_adlb %>%
216216
#' filter(USUBJID %in% ADSL$USUBJID) %>%
217-
#' tern::df_explicit_na() %>%
217+
#' df_explicit_na() %>%
218218
#' filter(AVISIT != "SCREENING")
219219
#' })
220220
#' join_keys(data) <- default_cdisc_join_keys[names(data)]

R/tm_g_km.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ template_g_km <- function(dataname = "ANL",
291291
#'
292292
#' data <- teal_data()
293293
#' data <- within(data, {
294+
#' library(dplyr)
295+
#' library(teal.modules.clinical)
294296
#' ADSL <- tmc_ex_adsl
295297
#' ADTTE <- tmc_ex_adtte
296298
#' })

R/tm_g_lineplot.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ template_g_lineplot <- function(dataname = "ANL",
4040
title = "Line Plot",
4141
y_lab = "",
4242
ggplot2_args = teal.widgets::ggplot2_args()) {
43-
4443
checkmate::assert_string(dataname)
4544
checkmate::assert_string(group_var)
4645
checkmate::assert_string(x)
@@ -237,11 +236,12 @@ template_g_lineplot <- function(dataname = "ANL",
237236
#'
238237
#' @examples
239238
#' library(nestcolor)
240-
#' library(dplyr)
241-
#' library(forcats)
242239
#'
243240
#' data <- teal_data()
244241
#' data <- within(data, {
242+
#' library(teal.modules.clinical)
243+
#' library(dplyr)
244+
#' library(forcats)
245245
#' ADSL <- tmc_ex_adsl
246246
#' ADLB <- tmc_ex_adlb %>%
247247
#' mutate(AVISIT == fct_reorder(AVISIT, AVISITN, min))

R/tm_g_pp_adverse_events.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ template_adverse_events <- function(dataname = "ANL",
209209
#'
210210
#' @examples
211211
#' library(nestcolor)
212-
#' library(dplyr)
213212
#'
214213
#' data <- teal_data()
215214
#' data <- within(data, {
215+
#' library(teal.modules.clinical)
216+
#' library(dplyr)
216217
#' ADAE <- tmc_ex_adae
217-
#' ADSL <- tmc_ex_adsl %>%
218-
#' filter(USUBJID %in% ADAE$USUBJID)
218+
#' ADSL <- filter(tmc_ex_adsl, USUBJID %in% ADAE$USUBJID)
219219
#' })
220220
#' join_keys(data) <- default_cdisc_join_keys[names(data)]
221221
#'

0 commit comments

Comments
 (0)