diff --git a/R/init.R b/R/init.R index baf8ffcd90..2cf058780d 100644 --- a/R/init.R +++ b/R/init.R @@ -219,8 +219,8 @@ init <- function(data, } is_modules_ok <- check_modules_datanames(modules, .teal_data_datanames(data)) - if (!isTRUE(is_modules_ok)) { - lapply(is_modules_ok$string, logger::log_warn) + if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) { + lapply(is_modules_ok$string, warning, call. = FALSE) } is_filter_ok <- check_filter_datanames(filter, .teal_data_datanames(data)) diff --git a/R/teal_data_module.R b/R/teal_data_module.R index fd43f167df..535516524d 100644 --- a/R/teal_data_module.R +++ b/R/teal_data_module.R @@ -152,3 +152,17 @@ teal_transform_module <- function(ui, server, label = "transform module") { class = c("teal_transform_module", "teal_data_module") ) } + + +#' Extract all `transformers` from `modules`. +#' +#' @param modules `teal_modules` or `teal_module` +#' @return A list of `teal_transform_module` nested in the same way as input `modules`. +#' @keywords internal +extract_transformers <- function(modules) { + if (inherits(modules, "teal_module")) { + modules$transformers + } else if (inherits(modules, "teal_modules")) { + lapply(modules$children, extract_transformers) + } +} diff --git a/man/extract_transformers.Rd b/man/extract_transformers.Rd new file mode 100644 index 0000000000..9af99abe12 --- /dev/null +++ b/man/extract_transformers.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/teal_data_module.R +\name{extract_transformers} +\alias{extract_transformers} +\title{Extract all \code{transformers} from \code{modules}.} +\usage{ +extract_transformers(modules) +} +\arguments{ +\item{modules}{\code{teal_modules} or \code{teal_module}} +} +\value{ +A list of \code{teal_transform_module} nested in the same way as input \code{modules}. +} +\description{ +Extract all \code{transformers} from \code{modules}. +} +\keyword{internal} diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 24efa4d119..d0a022330c 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -56,17 +56,44 @@ testthat::test_that("init throws when an empty `data` is used", { ) }) -testthat::test_that("init throws warning when datanames in modules incompatible w/ datanames in data", { - testthat::local_mocked_bindings(log_warn = warning, .package = "logger") +testthat::test_that( + "init throws warning when datanames in modules incompatible w/ datanames in data and there is no transformers", + { + testthat::expect_warning( + init( + data = teal.data::teal_data(mtcars = mtcars), + modules = list(example_module(datanames = "iris")) + ), + "Dataset \"iris\" is missing for tab 'example teal module'. Dataset available in data: \"mtcars\"." + ) + } +) - testthat::expect_warning( - init( - data = teal.data::teal_data(mtcars = mtcars), - modules = list(example_module(datanames = "iris")) - ), - "Dataset \"iris\" is missing for tab 'example teal module'. Dataset available in data: \"mtcars\"." - ) -}) +testthat::test_that( + "init does not throw warning when datanames in modules incompatible w/ datanames in data and there are transformers", + { + testthat::expect_no_warning( + init( + data = teal.data::teal_data(mtcars = mtcars), + modules = list( + example_module( + datanames = "iris", + transformers = list( + teal_transform_module( + ui = function(id) NULL, + server = function(id, data) { + moduleServer(id, function(input, output, session) { + NULL + }) + } + ) + ) + ) + ) + ) + ) + } +) testthat::test_that("init throws when dataname in filter incompatible w/ datanames in data", { testthat::expect_warning(