Skip to content

Commit ec16ae9

Browse files
m7prgogonzo
andauthored
module()$datanames : unify combined_datanames no matter what's the length of transformers (#1344)
`module()$datanames` are affected by `datanames` parameter and `datanames` coming out of `transformers`. So far this is not unified, and the outcome `$datanames` depend on the length of input of the transformers. They are different if the transformer has length 1. ```r # 0 transformers example_module("mod-1", transformers = list( ), datanames = c("ADSL", "ADTTE"))$datanames # > [1] "ADSL" "ADTTE" "all" # 1 transformer example_module("mod-1", transformers = list( teal_transform_module(ui = function(id) NULL, server = function(id, data) NULL) ), datanames = c("ADSL", "ADTTE"))$datanames [1] "all" # 2 transformers example_module("mod-1", transformers = list( teal_transform_module(ui = function(id) NULL, server = function(id, data) NULL), teal_transform_module(ui = function(id) NULL, server = function(id, data) NULL) ), datanames = c("ADSL", "ADTTE"))$datanames # [1] "ADSL" "ADTTE" "all" ``` The solution is up to discussion, but for now I plan to unify to return `union(datanames, transformers$datanames)` as a result. So if - `modules(datanames = "all"` and `transfomers(datanames = "all"` we get `"all"` - `modules(datanames = "custom"` and `transfomers(datanames = "all"` we get `c("custom", "all")` - `modules(datanames = "all"` and `transfomers(datanames = "custom"` we get `"all"` - `modules(datanames = "custom"` and `transfomers(datanames = "custom2"` we get `c("custom", "custom2")` The main reason for this change is to unify and to have custom datanames returned in `module()$datanames` if any custom names are passed via `module(datanames = ` parameter. --------- Signed-off-by: Marcin <[email protected]> Co-authored-by: Dawid Kałędkowski <[email protected]>
1 parent e4bb083 commit ec16ae9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

R/modules.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ module <- function(label = "module",
264264
}
265265
checkmate::assert_list(transformers, types = "teal_transform_module")
266266
transformer_datanames <- unlist(lapply(transformers, attr, "datanames"))
267-
combined_datanames <- if (identical(datanames, "all") || identical(transformer_datanames, "all")) {
267+
combined_datanames <- if (identical(datanames, "all") || any(sapply(transformer_datanames, identical, "all"))) {
268268
"all"
269269
} else {
270270
union(datanames, transformer_datanames)

tests/testthat/test-modules.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ testthat::test_that("module datanames is appended by its transformers datanames"
534534
testthat::expect_identical(out$datanames, c("c", "a", "b"))
535535
})
536536

537-
testthat::test_that("module datanames is set to 'all' if transformer $datanames is 'all'", {
537+
testthat::test_that("module datanames is set to 'all' if any transformer $datanames is 'all'", {
538538
transformer_w_datanames <- teal_transform_module(
539539
ui = function(id) NULL,
540540
server = function(id, data) {

0 commit comments

Comments
 (0)