Skip to content

Commit cfbeda8

Browse files
committed
Merge remote-tracking branch 'origin/main' into 479_mirai_lockfile@main
2 parents 4834f4e + 0812f26 commit cfbeda8

22 files changed

+268
-72
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: teal
33
Title: Exploratory Web Apps for Analyzing Clinical Trials Data
4-
Version: 0.15.2.9056
5-
Date: 2024-08-16
4+
Version: 0.15.2.9059
5+
Date: 2024-08-28
66
Authors@R: c(
77
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre"),
88
comment = c(ORCID = "0000-0001-9533-457X")),
@@ -90,6 +90,7 @@ Roxygen: list(markdown = TRUE)
9090
RoxygenNote: 7.3.2
9191
Collate:
9292
'TealAppDriver.R'
93+
'checkmate.R'
9394
'dummy_functions.R'
9495
'get_rcode_utils.R'
9596
'include_css_js.R'

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# teal 0.15.2.9056
1+
# teal 0.15.2.9059
22

33
### New features
44

R/checkmate.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#' Check that argument is reactive.
2+
#'
3+
#' @inherit checkmate::check_class params return
4+
#'
5+
#' @keywords internal
6+
check_reactive <- function(x, null.ok = FALSE) { # nolint: object_name_linter.
7+
if (!isTRUE(checkmate::test_class(x, classes = "reactive", null.ok = null.ok))) {
8+
cl <- class(x)
9+
return(sprintf(
10+
"Must be a reactive (i.e. inherit from 'reactive' class) but has class%s '%s'",
11+
if (length(cl) > 1L) "es" else "",
12+
paste0(cl, collapse = "','")
13+
))
14+
}
15+
return(TRUE)
16+
}
17+
#' @rdname check_reactive
18+
test_reactive <- function(x, null.ok = FALSE) { # nolint: object_name_linter.
19+
isTRUE(check_reactive(x, null.ok = null.ok))
20+
}
21+
#' @rdname check_reactive
22+
assert_reactive <- checkmate::makeAssertionFunction(check_reactive)
23+
24+
#' Capture error and decorate error message.
25+
#'
26+
#' @param x object to evaluate
27+
#' @param pre (`character(1)`) A string to prepend to error message
28+
#' @param post (`character(1)`) A string to append to error message
29+
#'
30+
#' @return `x` if no error, otherwise throws error with decorated message
31+
#'
32+
#' @keywords internal
33+
decorate_err_msg <- function(x, pre = character(0), post = character(0)) {
34+
tryCatch(
35+
x,
36+
error = function(e) {
37+
stop(
38+
"\n",
39+
pre,
40+
"\n",
41+
e$message,
42+
"\n",
43+
post,
44+
call. = FALSE
45+
)
46+
}
47+
)
48+
x
49+
}

R/init.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ init <- function(data,
216216
}
217217

218218
is_modules_ok <- check_modules_datanames(modules, .teal_data_datanames(data))
219-
if (!isTRUE(is_modules_ok)) {
220-
lapply(is_modules_ok$string, logger::log_warn)
219+
if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) {
220+
lapply(is_modules_ok$string, warning, call. = FALSE)
221221
}
222222

223223
is_filter_ok <- check_filter_datanames(filter, .teal_data_datanames(data))

R/module_data_summary.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ui_data_summary <- function(id) {
5454

5555
#' @rdname module_data_summary
5656
srv_data_summary <- function(id, teal_data) {
57-
checkmate::check_class(teal_data, "reactive")
57+
assert_reactive(teal_data)
5858
moduleServer(
5959
id = id,
6060
function(input, output, session) {
@@ -142,11 +142,13 @@ get_filter_overview <- function(teal_data) {
142142
datanames <- teal.data::datanames(teal_data())
143143
joinkeys <- teal.data::join_keys(teal_data())
144144
filtered_data_objs <- sapply(
145-
datanames, function(name) teal.code::get_env(teal_data())[[name]],
145+
datanames,
146+
function(name) teal.code::get_env(teal_data())[[name]],
146147
simplify = FALSE
147148
)
148149
unfiltered_data_objs <- sapply(
149-
datanames, function(name) teal.code::get_env(teal_data())[[paste0(name, "._raw_")]],
150+
datanames,
151+
function(name) teal.code::get_env(teal_data())[[paste0(name, "._raw_")]],
150152
simplify = FALSE
151153
)
152154

R/module_filter_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ui_filter_data <- function(id) {
2525

2626
#' @rdname module_filter_data
2727
srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active) {
28-
checkmate::assert_class(datasets, "reactive")
28+
assert_reactive(datasets)
2929
moduleServer(id, function(input, output, session) {
3030
output$panel <- renderUI({
3131
req(inherits(datasets(), "FilteredData"))

R/module_filter_manager.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ srv_filter_manager <- function(id, slices_global) {
173173
#' @rdname module_filter_manager
174174
srv_module_filter_manager <- function(id, module_fd, slices_global) {
175175
checkmate::assert_string(id)
176-
checkmate::assert_class(module_fd, "reactive")
176+
assert_reactive(module_fd)
177177
checkmate::assert_class(slices_global, ".slicesGlobal")
178178

179179
moduleServer(id, function(input, output, session) {

R/module_init_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ srv_init_data <- function(id, data, modules, filter = teal_slices()) {
7979
)
8080
} else if (inherits(data, "teal_data")) {
8181
reactiveVal(data)
82-
} else if (inherits(data, c("reactive", "reactiveVal"))) {
82+
} else if (test_reactive(data)) {
8383
.fallback_on_failure(this = data, that = reactive(req(FALSE)), label = "Reactive data")
8484
}
8585

R/module_nested_tabs.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ srv_teal_module <- function(id,
130130
reporter = teal.reporter::Reporter$new(),
131131
is_active = reactive(TRUE)) {
132132
checkmate::assert_string(id)
133-
checkmate::assert_class(data_rv, "reactive")
133+
assert_reactive(data_rv)
134134
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"))
135-
checkmate::assert_class(datasets, "reactive", null.ok = TRUE)
135+
assert_reactive(datasets, null.ok = TRUE)
136136
checkmate::assert_class(slices_global, ".slicesGlobal")
137137
checkmate::assert_class(reporter, "Reporter")
138138
UseMethod("srv_teal_module", modules)

R/module_teal_data.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ srv_teal_data <- function(id,
5555
modules = NULL,
5656
validate_shiny_silent_error = TRUE) {
5757
checkmate::assert_string(id)
58-
checkmate::assert_class(data, "reactive")
5958
checkmate::assert_class(data_module, "teal_data_module")
6059
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"), null.ok = TRUE)
6160

@@ -96,16 +95,16 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
9695
data,
9796
modules = NULL,
9897
validate_shiny_silent_error = FALSE) {
99-
moduleServer(id, function(input, output, session) {
100-
if (!is.reactive(data)) {
101-
stop("The `teal_data_module` passed to `data` must return a reactive expression.", call. = FALSE)
102-
}
98+
checkmate::assert_string(id)
99+
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"), null.ok = TRUE)
100+
checkmate::assert_flag(validate_shiny_silent_error)
103101

104-
data_out_rv <- reactive(tryCatch(data(), error = function(e) e))
102+
moduleServer(id, function(input, output, session) {
103+
data_out_r <- reactive(tryCatch(data(), error = function(e) e))
105104

106105
data_validated <- reactive({
107106
# custom module can return error
108-
data_out <- data_out_rv()
107+
data_out <- data_out_r()
109108

110109
# there is an empty reactive cycle on init!
111110
if (inherits(data_out, "shiny.silent.error") && identical(data_out$message, "")) {
@@ -116,9 +115,9 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
116115
need(
117116
FALSE,
118117
paste(
119-
strip_style(data_out$message),
118+
"Shiny error when executing the `data` module",
120119
"Check your inputs or contact app developer if error persists.",
121-
sep = ifelse(identical(data_out$message, ""), "", "\n")
120+
collapse = "\n"
122121
)
123122
)
124123
)
@@ -130,23 +129,24 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
130129
validate(
131130
need(
132131
FALSE,
133-
paste(
134-
"Error when executing `teal_data_module` passed to `data`:\n ",
132+
paste0(
133+
"Error when executing the `data` module:",
135134
strip_style(paste(data_out$message, collapse = "\n")),
136-
"\n Check your inputs or contact app developer if error persists."
135+
"Check your inputs or contact app developer if error persists.",
136+
collapse = "\n"
137137
)
138138
)
139139
)
140140
}
141141

142142
validate(
143143
need(
144-
inherits(data_out, "teal_data"),
145-
paste(
146-
"Error: `teal_data_module` passed to `data` failed to return `teal_data` object, returned",
147-
strip_style(toString(sQuote(class(data_out)))),
148-
"instead.",
149-
"\n Check your inputs or contact app developer if error persists."
144+
checkmate::test_class(data_out, "teal_data"),
145+
paste0(
146+
"Assertion on return value from the 'data' module failed:",
147+
checkmate::test_class(data_out, "teal_data"),
148+
"Check your inputs or contact app developer if error persists.",
149+
collapse = "\n"
150150
)
151151
)
152152
)
@@ -160,7 +160,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
160160
})
161161

162162
output$shiny_warnings <- renderUI({
163-
if (inherits(data_out_rv(), "teal_data")) {
163+
if (inherits(data_out_r(), "teal_data")) {
164164
is_modules_ok <- check_modules_datanames(modules = modules, datanames = .teal_data_ls(data_validated()))
165165
if (!isTRUE(is_modules_ok)) {
166166
tags$div(
@@ -191,8 +191,8 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
191191
#' @return `reactive` `teal_data`
192192
#' @keywords internal
193193
.fallback_on_failure <- function(this, that, label) {
194-
checkmate::assert_class(this, "reactive")
195-
checkmate::assert_class(that, "reactive")
194+
assert_reactive(this)
195+
assert_reactive(that)
196196
checkmate::assert_string(label)
197197

198198
reactive({

0 commit comments

Comments
 (0)