From 635ce743bb46d6ddcd98d2bbdde9c0d55079f448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:56:38 +0100 Subject: [PATCH 1/5] fix: allow non-standard datanames in teal .raw_data --- R/module_filter_data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/module_filter_data.R b/R/module_filter_data.R index 959fd867e..388aeb241 100644 --- a/R/module_filter_data.R +++ b/R/module_filter_data.R @@ -56,7 +56,7 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active) data, paste0( ".raw_data <- list2env(list(", - toString(sprintf("%1$s = %1$s", datanames)), + toString(sprintf("%1$s = %1$s", sapply(datanames, as.name))), "))\n", "lockEnvironment(.raw_data) #@linksto .raw_data" # this is environment and it is shared by qenvs. CAN'T MODIFY! ) From 3f561ad472e7ee48e776a5641f292e941d61b0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:29:05 +0100 Subject: [PATCH 2/5] tests: adds preliminary tests --- tests/testthat/test-module_teal.R | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index e18c975e1..a07af4d4c 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -2216,3 +2216,106 @@ testthat::describe("srv_teal snapshot manager", { ) }) }) + +testthat::describe("Datanames with special symbols", { + testthat::it("are detected as datanames when defined as 'all'", { + shiny::testServer( + app = srv_teal, + args = list( + id = "test", + data = teal.data::teal_data( + iris = iris, + `%a_pipe%` = function(lhs, rhs) paste(lhs, rhs) + ), + modules = modules(module("module_1", server = function(id, data) data)), + filter = teal_slices( + module_specific = TRUE + ) + ), + expr = { + session$setInputs("teal_modules-active_tab" = "module_1") + session$flushReact() + + testthat::expect_setequal( + ls( + teal.code::get_env(modules_output$module_1()()), + all.names = TRUE + ), + c(".raw_data", "iris", "%a_pipe%") + ) + } + ) + }) + + testthat::it("are present in datanames when used in pre-processing code, but not defined in datanames", { + shiny::testServer( + app = srv_teal, + args = list( + id = "test", + data = within( + teal.data::teal_data(), + { + iris <- iris + mtcars <- mtcars + `_a variable with spaces_` <- "new_column" + iris <- cbind(iris, data.frame(`_a variable with spaces_`)) + } + ), + modules = modules( + module("module_1", server = function(id, data) data, datanames = "iris") + ) + ), + expr = { + session$setInputs("teal_modules-active_tab" = "module_1") + session$flushReact() + + testthat::expect_setequal( + ls( + teal.code::get_env(modules_output$module_1()()), + all.names = TRUE + ), + c(".raw_data", "iris", "_a variable with spaces_") + ) + } + ) + }) + + testthat::it("(when used as non-native pipe) are present in datanames in the pre-processing code", { + shiny::testServer( + app = srv_teal, + args = list( + id = "test", + data = within( + teal.data::teal_data(), + { + iris <- iris + mtcars <- mtcars + `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs) + iris <- iris %cbind% data.frame("new_column") + } + ), + modules = modules( + module("module_1", server = function(id, data) data, , datanames = c("iris")) + ), + filter = teal_slices( + module_specific = TRUE + ) + ), + expr = { + session$setInputs("teal_modules-active_tab" = "module_1") + session$flushReact() + + testthat::expect_contains( + strsplit( + x = teal.code::get_code(modules_output$module_1()()), + split = "\n" + )[[1]], + c( + "`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)", + ".raw_data <- list2env(list(iris = iris))" + ) + ) + } + ) + }) +}) From 3546c3d344098d40f6c905919b567e251cf3e526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:13:08 +0100 Subject: [PATCH 3/5] tests: fix test to avoid #1390 --- tests/testthat/test-module_teal.R | 72 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index a07af4d4c..93bc5f92e 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -2247,7 +2247,7 @@ testthat::describe("Datanames with special symbols", { ) }) - testthat::it("are present in datanames when used in pre-processing code, but not defined in datanames", { + testthat::it("are present in datanames when used in pre-processing code", { shiny::testServer( app = srv_teal, args = list( @@ -2262,13 +2262,12 @@ testthat::describe("Datanames with special symbols", { } ), modules = modules( - module("module_1", server = function(id, data) data, datanames = "iris") + module("module_1", server = function(id, data) data, datanames = c("iris", "_a variable with spaces_")) ) ), expr = { session$setInputs("teal_modules-active_tab" = "module_1") session$flushReact() - testthat::expect_setequal( ls( teal.code::get_env(modules_output$module_1()()), @@ -2281,41 +2280,44 @@ testthat::describe("Datanames with special symbols", { }) testthat::it("(when used as non-native pipe) are present in datanames in the pre-processing code", { - shiny::testServer( - app = srv_teal, - args = list( - id = "test", - data = within( - teal.data::teal_data(), - { - iris <- iris - mtcars <- mtcars - `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs) - iris <- iris %cbind% data.frame("new_column") - } - ), - modules = modules( - module("module_1", server = function(id, data) data, , datanames = c("iris")) + testthat::expect_warning( + shiny::testServer( + app = srv_teal, + args = list( + id = "test", + data = within( + teal.data::teal_data(), + { + iris <- iris + mtcars <- mtcars + `%cbind%` <- function(lhs, rhs) cbind(lhs, rhs) + iris <- iris %cbind% data.frame("new_column") + } + ), + modules = modules( + module("module_1", server = function(id, data) data, , datanames = c("iris")) + ), + filter = teal_slices( + module_specific = TRUE + ) ), - filter = teal_slices( - module_specific = TRUE - ) - ), - expr = { - session$setInputs("teal_modules-active_tab" = "module_1") - session$flushReact() + expr = { + session$setInputs("teal_modules-active_tab" = "module_1") + session$flushReact() - testthat::expect_contains( - strsplit( - x = teal.code::get_code(modules_output$module_1()()), - split = "\n" - )[[1]], - c( - "`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)", - ".raw_data <- list2env(list(iris = iris))" + testthat::expect_contains( + strsplit( + x = teal.code::get_code(modules_output$module_1()()), + split = "\n" + )[[1]], + c( + "`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)", + ".raw_data <- list2env(list(iris = iris))" + ) ) - ) - } + } + ), + "'package:teal' may not be available when loading" ) }) }) From 92f56463bc4694fb12fb96964b979e706495cabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:26:12 +0100 Subject: [PATCH 4/5] lint: add exception for variable name with spaces --- tests/testthat/test-module_teal.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-module_teal.R b/tests/testthat/test-module_teal.R index 93bc5f92e..b8878e566 100644 --- a/tests/testthat/test-module_teal.R +++ b/tests/testthat/test-module_teal.R @@ -2257,7 +2257,7 @@ testthat::describe("Datanames with special symbols", { { iris <- iris mtcars <- mtcars - `_a variable with spaces_` <- "new_column" + `_a variable with spaces_` <- "new_column" # nolint: object_name. iris <- cbind(iris, data.frame(`_a variable with spaces_`)) } ), From eaf1694164f655575b574f785e3425e76d9379f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 25 Oct 2024 08:55:23 +0100 Subject: [PATCH 5/5] chore: empty commit to retrigger CI