diff --git a/R/module_nested_tabs.R b/R/module_nested_tabs.R index 588227498a..82f525cc18 100644 --- a/R/module_nested_tabs.R +++ b/R/module_nested_tabs.R @@ -294,7 +294,7 @@ srv_teal_module.teal_module <- function(id, req(inherits(transformed_teal_data(), "teal_data")) all_teal_data <- transformed_teal_data() module_datanames <- .resolve_module_datanames(data = all_teal_data, modules = modules) - .subset_teal_data(all_teal_data, module_datanames) + all_teal_data[c(module_datanames, ".raw_data")] }) srv_validate_reactive_teal_data( diff --git a/R/teal_data_utils.R b/R/teal_data_utils.R index f5244c5736..2b5b51c8b6 100644 --- a/R/teal_data_utils.R +++ b/R/teal_data_utils.R @@ -11,7 +11,6 @@ #' @param data (`teal_data`) #' @param code (`character`) code to append to the object's code slot. #' @param objects (`list`) objects to append to object's environment. -#' @param datanames (`character`) names of the datasets #' @return modified `teal_data` #' @keywords internal #' @name teal_data_utilities @@ -20,10 +19,7 @@ NULL #' @rdname teal_data_utilities .append_evaluated_code <- function(data, code) { checkmate::assert_class(data, "teal_data") - data@code <- c(data@code, code) - data@id <- c(data@id, max(data@id) + 1L + seq_along(code)) - data@messages <- c(data@messages, rep("", length(code))) - data@warnings <- c(data@warnings, rep("", length(code))) + data@code <- c(data@code, code2list(code)) methods::validObject(data) data } @@ -37,27 +33,3 @@ NULL data@.xData <- new_env data } - -#' @rdname teal_data_utilities -.subset_teal_data <- function(data, datanames) { - checkmate::assert_class(data, "teal_data") - checkmate::assert_class(datanames, "character") - datanames_corrected <- intersect(datanames, names(data)) - datanames_corrected_with_raw <- c(datanames_corrected, ".raw_data") - if (!length(datanames_corrected)) { - return(teal_data()) - } - - new_data <- do.call( - teal.data::teal_data, - args = c( - mget(x = datanames_corrected_with_raw, envir = as.environment(data)), - list( - code = teal.code::get_code(data, names = datanames_corrected_with_raw), - join_keys = teal.data::join_keys(data)[datanames_corrected] - ) - ) - ) - new_data@verified <- data@verified - new_data -} diff --git a/R/zzz.R b/R/zzz.R index a991d041f2..62c8029561 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -37,3 +37,4 @@ RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") # nolint: object_n # Use non-exported function(s) from teal.code # This one is here because lang2calls should not be exported from teal.code lang2calls <- getFromNamespace("lang2calls", "teal.code") +code2list <- getFromNamespace("code2list", "teal.data") diff --git a/man/teal_data_utilities.Rd b/man/teal_data_utilities.Rd index f7943f3910..0fdcaa6653 100644 --- a/man/teal_data_utilities.Rd +++ b/man/teal_data_utilities.Rd @@ -4,14 +4,11 @@ \alias{teal_data_utilities} \alias{.append_evaluated_code} \alias{.append_modified_data} -\alias{.subset_teal_data} \title{\code{teal_data} utils} \usage{ .append_evaluated_code(data, code) .append_modified_data(data, objects) - -.subset_teal_data(data, datanames) } \arguments{ \item{data}{(\code{teal_data})} @@ -19,8 +16,6 @@ \item{code}{(\code{character}) code to append to the object's code slot.} \item{objects}{(\code{list}) objects to append to object's environment.} - -\item{datanames}{(\code{character}) names of the datasets} } \value{ modified \code{teal_data} diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index dd60c2c619..2e91a13f57 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -1413,10 +1413,10 @@ testthat::describe("srv_teal filters", { c( "iris <- iris", "mtcars <- mtcars", - sprintf('stopifnot(rlang::hash(iris) == "%s")', rlang::hash(iris)), - sprintf('stopifnot(rlang::hash(mtcars) == "%s")', rlang::hash(mtcars)), + sprintf('stopifnot(rlang::hash(iris) == "%s") # @linksto iris', rlang::hash(iris)), + sprintf('stopifnot(rlang::hash(mtcars) == "%s") # @linksto mtcars', rlang::hash(mtcars)), ".raw_data <- list2env(list(iris = iris, mtcars = mtcars))", - "lockEnvironment(.raw_data)", + "lockEnvironment(.raw_data) # @linksto .raw_data", "mtcars <- dplyr::filter(mtcars, cyl == 4)" ), collapse = "\n" @@ -1591,10 +1591,10 @@ testthat::describe("srv_teal teal_module(s) transformer", { expected_code <- paste(collapse = "\n", c( "iris <- iris", "mtcars <- mtcars", - sprintf('stopifnot(rlang::hash(iris) == "%s")', rlang::hash(iris)), - sprintf('stopifnot(rlang::hash(mtcars) == "%s")', rlang::hash(mtcars)), + sprintf('stopifnot(rlang::hash(iris) == "%s") # @linksto iris', rlang::hash(iris)), + sprintf('stopifnot(rlang::hash(mtcars) == "%s") # @linksto mtcars', rlang::hash(mtcars)), ".raw_data <- list2env(list(iris = iris, mtcars = mtcars))", - "lockEnvironment(.raw_data)", + "lockEnvironment(.raw_data) # @linksto .raw_data", 'iris <- dplyr::filter(iris, Species == "versicolor")', "mtcars <- dplyr::filter(mtcars, cyl == 6)", "iris <- head(iris, n = 6)", @@ -1637,10 +1637,10 @@ testthat::describe("srv_teal teal_module(s) transformer", { expected_code <- paste(collapse = "\n", c( "iris <- iris", "mtcars <- mtcars", - sprintf('stopifnot(rlang::hash(iris) == "%s")', rlang::hash(iris)), - sprintf('stopifnot(rlang::hash(mtcars) == "%s")', rlang::hash(mtcars)), + sprintf('stopifnot(rlang::hash(iris) == "%s") # @linksto iris', rlang::hash(iris)), + sprintf('stopifnot(rlang::hash(mtcars) == "%s") # @linksto mtcars', rlang::hash(mtcars)), ".raw_data <- list2env(list(iris = iris, mtcars = mtcars))", - "lockEnvironment(.raw_data)", + "lockEnvironment(.raw_data) # @linksto .raw_data", "mtcars <- dplyr::filter(mtcars, cyl == 4)", "iris <- head(iris, n = 6)", "mtcars <- head(mtcars, n = 6)" @@ -2445,7 +2445,7 @@ testthat::describe("Datanames with special symbols", { } ), modules = modules( - module("module_1", server = function(id, data) data, , datanames = c("iris")) + module("module_1", server = function(id, data) data, datanames = c("iris")) ), filter = teal_slices( module_specific = TRUE @@ -2483,7 +2483,7 @@ testthat::describe("teal.data code with a function defined", { } })), modules = modules(module("module_1", server = function(id, data) data)) - ), , + ), expr = { session$setInputs("teal_modules-active_tab" = "module_1") session$flushReact() @@ -2545,9 +2545,9 @@ testthat::describe("teal.data code with a function defined", { "y <- x + 1", "y + 3", "}", - sprintf("stopifnot(rlang::hash(deparse1(fun)) == \"%s\")", local_env$hash), + sprintf("stopifnot(rlang::hash(deparse1(fun)) == \"%s\") # @linksto fun", local_env$hash), ".raw_data <- list2env(list(fun = fun))", - "lockEnvironment(.raw_data)" + "lockEnvironment(.raw_data) # @linksto .raw_data" ) ) } diff --git a/tests/testthat/test-shinytest2-show-rcode.R b/tests/testthat/test-shinytest2-show-rcode.R index 20901cd270..a7504573f0 100644 --- a/tests/testthat/test-shinytest2-show-rcode.R +++ b/tests/testthat/test-shinytest2-show-rcode.R @@ -42,16 +42,15 @@ testthat::test_that("e2e: teal app initializes with Show R Code modal", { ) # Check R code output. - testthat::expect_identical( - app$get_text(app$active_module_element("rcode-verbatim_content")), - paste( + testthat::expect_setequal( + strsplit(app$get_text(app$active_module_element("rcode-verbatim_content")), "\n")[[1]], + c( "iris <- iris", "mtcars <- mtcars", - sprintf('stopifnot(rlang::hash(iris) == "%s")', rlang::hash(iris)), - sprintf('stopifnot(rlang::hash(mtcars) == "%s")', rlang::hash(mtcars)), + sprintf('stopifnot(rlang::hash(iris) == "%s") # @linksto iris', rlang::hash(iris)), + sprintf('stopifnot(rlang::hash(mtcars) == "%s") # @linksto mtcars', rlang::hash(mtcars)), ".raw_data <- list2env(list(iris = iris, mtcars = mtcars))", - "lockEnvironment(.raw_data)", - sep = "\n" + "lockEnvironment(.raw_data) # @linksto .raw_data" ) )