Skip to content

Commit

Permalink
1031 drop list support (#1051)
Browse files Browse the repository at this point in the history
Fixes #1031
  • Loading branch information
chlebowa authored Jan 17, 2024
1 parent 7278bd5 commit d03cacc
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 74 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

### New features

* `data` argument in `init` now accepts `teal_data` and `teal_data_module`.
* Added `landing_popup_module` function which creates a module that will display a popup when the app starts. The popup will block access to the app until it is dismissed.
* Filter state snapshots can now be uploaded from file. See `?snapshot`.
* Added `as_tdata` function to facilitate migration of modules to the new `teal_data` class.
* Added `build_app_title` function to facilitate adding favicons to app title.

### Breaking changes

* `data` argument in `init` now accepts only `teal_data` and `teal_data_module`.
* `tdata` has been deprecated and replaced with `teal_data`. Support for `tdata` passed to the `data` argument in `module(server)` will be removed in the next release.
* `module(ui)` argument no longer accepts `data` and `datasets` arguments. All data dependent logic should be set in the `server` function.
* `module(server)` argument deprecated `datasets` argument. `teal_module`s' `server` functions should accept `data` (`teal_data`) instead.
Expand Down
15 changes: 3 additions & 12 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
#' When initializing the `teal` app, if `datanames` are not set for the `teal_data` object,
#' defaults from the `teal_data` environment will be used.
#'
#' @param data (`teal_data`, `teal_data_module`, `named list`)\cr
#' `teal_data` object as returned by [teal.data::teal_data()] or
#' `teal_data_module` or simply a list of a named list of objects
#' (`data.frame` or `MultiAssayExperiment`).
#' @param data (`teal_data`, `teal_data_module`)\cr
#' `teal_data` object as returned by [teal.data::teal_data()] or `teal_data_module`.
#' @param modules (`list`, `teal_modules` or `teal_module`)\cr
#' nested list of `teal_modules` or `teal_module` objects or a single
#' `teal_modules` or `teal_module` object. These are the specific output modules which
Expand Down Expand Up @@ -119,14 +117,7 @@ init <- function(data,
)
)
}
checkmate::assert(
.var.name = "data",
checkmate::check_multi_class(data, c("teal_data", "teal_data_module")),
checkmate::check_list(data, names = "named")
)
if (is.list(data) && !inherits(data, "teal_data_module")) {
data <- do.call(teal.data::teal_data, data)
}
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module"))

## `modules`
checkmate::assert(
Expand Down
2 changes: 1 addition & 1 deletion R/teal_slices.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#' )
#'
#' app <- init(
#' data = list(iris = iris, mtcars = mtcars),
#' data = teal_data(iris = iris, mtcars = mtcars),
#' modules = list(
#' module("module1"),
#' module("module2")
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ create_app_id <- function(data, modules) {
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module"))
checkmate::assert_class(modules, "teal_modules")

hashables <- c(data, modules)
hashables <- list(data = data, modules = modules)
hashables$data <- if (inherits(hashables$data, "teal_data")) {
as.list(hashables$data@env)
} else if (inherits(data, "teal_data_module")) {
Expand Down
6 changes: 2 additions & 4 deletions man/init.Rd

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

6 changes: 2 additions & 4 deletions man/srv_teal_with_splash.Rd

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

2 changes: 1 addition & 1 deletion man/teal_slices.Rd

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

6 changes: 2 additions & 4 deletions man/ui_teal_with_splash.Rd

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

60 changes: 14 additions & 46 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
example_module <- teal:::example_module

# data ----
testthat::test_that("init data accepts teal_data object", {
testthat::expect_no_error(
init(
data = teal.data::teal_data(iris = iris),
modules = modules(teal:::example_module())
)
)
})

testthat::test_that("init data accepts a single dataframe", {
testthat::expect_no_error(
init(data = list(iris = iris), modules = modules(example_module()))
)
})

testthat::test_that("init data accepts a list of single dataframe without renaming", {
testthat::skip("todo: should we support data as unnamed list in teal?")
testthat::expect_no_error(
init(data = list(iris, mtcars), modules = modules(example_module()))
)
})

testthat::test_that("init data accepts a list of single dataframe with renaming", {
testthat::expect_no_error(
init(
data = list(iris2 = iris),
modules = modules(example_module())
)
)
})

testthat::test_that("init data accepts a single MultiAssayExperiment object", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_no_error(
init(data = list(MAE = miniACC), modules = modules(example_module()))
)
})

testthat::test_that("init data accepts a list of a single MultiAssayExperiment object with renaming", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_no_error(init(data = list(x = miniACC), modules = modules(example_module())))
})

testthat::test_that("init data acceptsa mixed list of MultiAssayExperiment object and data.frame", {
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_no_error(init(data = list(x = miniACC, y = head(iris)), modules = modules(example_module())))
})

testthat::test_that("init data accepts teal_data_module", {
testthat::expect_no_error(
init(
Expand All @@ -55,40 +19,44 @@ testthat::test_that("init data accepts teal_data_module", {
)
})


# modules ----
testthat::test_that("init modules accepts a teal_modules object", {
mods <- modules(example_module(), example_module())
testthat::expect_no_error(init(data = list(iris = iris), modules = mods))
testthat::expect_no_error(init(data = teal_data(iris = iris), modules = mods))
})

testthat::test_that("init modules accepts a list of teal_module elements", {
mods <- list(example_module(), example_module())
testthat::expect_no_error(init(data = list(iris = iris), modules = mods))
testthat::expect_no_error(init(data = teal_data(iris = iris), modules = mods))
})

testthat::test_that("init modules accepts a teal_module object", {
mods <- example_module()
testthat::expect_no_error(init(data = list(iris = iris), modules = mods))
testthat::expect_no_error(init(data = teal_data(iris = iris), modules = mods))
})

# filter ----
testthat::test_that("init filter accepts `teal_slices`", {
fs <- teal.slice::teal_slices(
teal.slice::teal_slice(dataname = "iris", varname = "species", selected = "setosa")
)
testthat::expect_no_error(init(data = list(iris = iris), modules = modules(example_module()), filter = fs))
testthat::expect_no_error(init(data = teal_data(iris = iris), modules = modules(example_module()), filter = fs))
testthat::expect_error(
init(data = list(iris = iris), modules = modules(example_module()), filter = unclass(fs)),
init(data = teal_data(iris = iris), modules = modules(example_module()), filter = unclass(fs)),
"Assertion on 'filter' failed"
)
})

# data + modules ----
testthat::test_that("init throws when data has no datanames", {
testthat::expect_error(
init(data = teal_data(), modules = list(example_module())),
"`data` object has no datanames and its environment is empty"
)
})

testthat::test_that("init throws when incompatible module's datanames", {
testthat::test_that("init throws when datanames in modules incompatible w/ datanames in data", {
msg <- "Module 'example teal module' uses datanames not available in 'data'"
testthat::expect_error(
init(
Expand All @@ -99,7 +67,7 @@ testthat::test_that("init throws when incompatible module's datanames", {
)
})

testthat::test_that("init throws when incompatible filter's datanames", {
testthat::test_that("init throws when dataname in filter incompatible w/ datanames in data", {
testthat::expect_warning(
init(
data = teal_data(mtcars = mtcars),
Expand Down

0 comments on commit d03cacc

Please sign in to comment.