Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE, packages = c("roxy.shinylive"))
RoxygenNote: 7.3.3
Remotes:
insightsengineering/teal.slice@main
Collate:
'TealAppDriver.R'
'after.R'
Expand Down
2 changes: 1 addition & 1 deletion R/checkmate.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ check_reactive <- function(x, null.ok = FALSE) { # nolint: object_name_linter.
paste0(cl, collapse = "','")
))
}
return(TRUE)
TRUE
}
#' @rdname check_reactive
test_reactive <- function(x, null.ok = FALSE) { # nolint: object_name_linter.
Expand Down
4 changes: 2 additions & 2 deletions R/module_transform_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ui_transform_teal_data <- function(id, transformators, class = "well") {
transformators <- list(transformators)
}
checkmate::assert_list(transformators, "teal_transform_module")
names(transformators) <- sprintf("transform_%d", seq_len(length(transformators)))
names(transformators) <- sprintf("transform_%d", seq_along(transformators))

lapply(
names(transformators),
Expand Down Expand Up @@ -75,7 +75,7 @@ srv_transform_teal_data <- function(id, data, transformators, modules = NULL, is
transformators <- list(transformators)
}
checkmate::assert_list(transformators, "teal_transform_module", null.ok = TRUE)
names(transformators) <- sprintf("transform_%d", seq_len(length(transformators)))
names(transformators) <- sprintf("transform_%d", seq_along(transformators))

moduleServer(id, function(input, output, session) {
module_output <- Reduce(
Expand Down
60 changes: 23 additions & 37 deletions R/teal_slices.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,43 +123,6 @@ teal_slices <- function(...,
})
}


#' @rdname teal_slices
#' @export
#' @keywords internal
#'
as.teal_slices <- function(x) { # nolint: object_name.
checkmate::assert_list(x)
lapply(x, checkmate::assert_list, names = "named", .var.name = "list element")

attrs <- attributes(unclass(x))
ans <- lapply(x, function(x) if (is.teal_slice(x)) x else as.teal_slice(x))
do.call(teal_slices, c(ans, attrs))
}


#' @rdname teal_slices
#' @export
#' @keywords internal
#'
c.teal_slices <- function(...) {
x <- list(...)
checkmate::assert_true(all(vapply(x, is.teal_slices, logical(1L))), .var.name = "all arguments are teal_slices")

all_attributes <- lapply(x, attributes)
all_attributes <- coalesce_r(all_attributes)
all_attributes <- all_attributes[names(all_attributes) != "class"]

do.call(
teal_slices,
c(
unique(unlist(x, recursive = FALSE)),
all_attributes
)
)
}


#' Deep copy `teal_slices`
#'
#' it's important to create a new copy of `teal_slices` when
Expand All @@ -179,3 +142,26 @@ deep_copy_filter <- function(filter) {
filter_copy
})
}


#' Copy functions to `teal` namespace
#'
#' Useful when we require function from other namespace where this function
#' calls other functions from `teal` namespace (see `as.teal_slices`, `c.teal_slices`).
#' @keywords internal
.copy_to_teal <- function(fun) {
environment(fun) <- getNamespace("teal")
fun
}

#' @rdname teal_slices
#' @export
#' @keywords internal
#'
as.teal_slices <- .copy_to_teal(teal.slice::as.teal_slices) # nolint: object_name_linter.

#' @rdname teal_slices
#' @export
#' @keywords internal
#'
c.teal_slices <- .copy_to_teal(utils::getS3method("c", "teal_slices", envir = getNamespace("teal.slice")))
13 changes: 13 additions & 0 deletions man/dot-copy_to_teal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 49 additions & 4 deletions tests/testthat/test-teal_slices.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ testthat::test_that(
}
)


# from different file


testthat::test_that("teal_slices mapping should be an empty list or a named list or missing", {
testthat::expect_no_error(
teal_slices(
Expand Down Expand Up @@ -156,3 +152,52 @@ testthat::test_that("teal_slices mapping should be an empty list or a named list
"Assertion.+failed"
)
})

testthat::test_that("c.teal_slices combines mapping of teal_slices objects", {
tss1 <- teal_slices(
teal.slice::teal_slice(dataname = "data1", varname = "var1", id = "test1"),
module_specific = TRUE,
mapping = list(module1 = "test1")
)
tss2 <- teal_slices(
teal.slice::teal_slice(dataname = "data2", varname = "var2", id = "test2"),
module_specific = TRUE,
mapping = list(module2 = "test2")
)
testthat::expect_identical(
c(tss1, tss2),
teal_slices(
tss1[[1]], tss2[[1]],
module_specific = TRUE,
mapping = list(
module1 = "test1",
module2 = "test2"
)
)
)
})

testthat::test_that("c.teal_slices combines mapping of two equal slices objects but ignores adding duplicated one", {
tss1 <- teal_slices(
teal.slice::teal_slice(dataname = "data1", varname = "var1", id = "test1"),
module_specific = TRUE,
mapping = list(module1 = "test1")
)
tss2 <- teal_slices(
teal.slice::teal_slice(dataname = "data1", varname = "var1", id = "test1"),
module_specific = TRUE,
mapping = list(module2 = "test1")
)

testthat::expect_identical(
c(tss1, tss2),
teal_slices(
tss1[[1]],
module_specific = TRUE,
mapping = list(
module1 = "test1",
module2 = "test1"
)
)
)
})
Loading