Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert check to assert #795

Merged
merged 8 commits into from
Jan 12, 2023
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
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Major breaking changes

* The use of `datasets` argument in `teal` `modules` has been deprecated and will be removed in a future release. Please use `data` argument instead. `data` is of type `tdata`; see "Creating custom modules" vignettes and function documentation of `teal::new_tdata` for further details.
* The use of `datasets` argument in `modules` has been deprecated and will be removed in a future release. Please use `data` argument instead. `data` is of type `tdata`; see "Creating custom modules" vignettes and function documentation of `teal::new_tdata` for further details.

### Breaking changes

Expand All @@ -11,6 +11,7 @@
### New features

* Added the `validate_inputs` and `validate_inputs_segregated` functions that transfer input validation messages to app output.
* `modules` argument of `init` accepts `teal_module` type of object. There is no need to wrap up a single module in `modules()` or `list()`.

### Miscellaneous

Expand Down
2 changes: 1 addition & 1 deletion R/example_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' dataset("IRIS", iris),
#' dataset("MTCARS", mtcars)
#' ),
#' modules = modules(example_module())
#' modules = example_module()
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
Expand Down
2 changes: 1 addition & 1 deletion R/get_rcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ get_rcode_srv <- function(id,
modal_title = "R Code",
code_header = "Automatically generated R code",
disable_buttons = reactiveVal(FALSE)) {
checkmate::check_class(disable_buttons, c("reactive", "function"))
checkmate::assert_class(disable_buttons, c("reactive", "function"))

lifecycle::deprecate_warn(
when = "0.12.1",
Expand Down
12 changes: 8 additions & 4 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#' NOTE: teal does not guarantee reproducibility of the code when names of the list elements
#' do not match the original object names. To ensure reproducibility please use [teal.data::teal_data()]
#' or [teal.data::cdisc_data()] with `check = TRUE` enabled.
#' @param modules (`list` or `teal_modules`)\cr
#' nested list of `teal_modules` or `module` objects. See [modules()] and [module()] for
#' @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
#' will be displayed in the teal application. See [modules()] and [module()] for
#' more details.
#' @param title (`NULL` or `character`)\cr
#' The browser window title (defaults to the host URL of the page).
Expand Down Expand Up @@ -161,14 +163,16 @@ init <- function(data,

checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert_class(data, "TealData")
checkmate::check_list(modules)
checkmate::check_class(modules, "teal_modules")
checkmate::assert_multi_class(modules, c("teal_module", "list", "teal_modules"))
checkmate::assert_list(filter, min.len = 0, names = "unique")
checkmate::assert_subset(names(filter), choices = teal.data::get_dataname(data))
checkmate::assert_character(id, max.len = 1, any.missing = FALSE)

teal.logger::log_system_info()

if (is(modules, "teal_module")) {
nikolas-burkoff marked this conversation as resolved.
Show resolved Hide resolved
modules <- list(modules)
}
if (is(modules, "list")) {
modules <- do.call(teal::modules, modules)
}
Expand Down
2 changes: 1 addition & 1 deletion R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ui_nested_tabs.teal_modules <- function(id, modules, datasets, depth = 0L) {
#' @export
#' @keywords internal
ui_nested_tabs.teal_module <- function(id, modules, datasets, depth = 0L) {
checkmate::check_class(datasets, "FilteredData")
checkmate::assert_class(datasets, "FilteredData")
args <- isolate(teal.transform::resolve_delayed(modules$ui_args, datasets))
args <- c(list(id = id), args)

Expand Down
2 changes: 2 additions & 0 deletions R/module_tabs_with_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' panel is inserted at the right of the modules at depth 1 and not at the leaves.
#'
#' @inheritParams ui_teal_with_splash
#' @param modules (`teal_modules`) the modules which will be displayed in the teal application.
#' See [modules()] and [module()] for more details.
#' @inheritParams init
#' @param datasets (`FilteredData`)\cr
#' object to store filter state and filtered datasets, shared across modules. For more
Expand Down
3 changes: 3 additions & 0 deletions R/module_teal_with_splash.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ ui_teal_with_splash <- function(id,
#' Please also refer to the doc of [init()].
#'
#' @inheritParams init
#' @param modules `teal_modules` object containing the output modules which
#' will be displayed in the teal application. See [modules()] and [module()] for
#' more details.
#' @inheritParams shiny::moduleServer
#' @return `reactive`, return value of [srv_teal()]
#' @export
Expand Down
4 changes: 1 addition & 3 deletions R/modules_debugging.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#' ),
#' code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"
#' ),
#' modules = modules(
#' teal:::filter_calls_module()
#' ),
#' modules = teal:::filter_calls_module(),
#' header = "Simple teal app"
#' )
#' if (interactive()) {
Expand Down
2 changes: 1 addition & 1 deletion man/example_module.Rd

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

4 changes: 1 addition & 3 deletions man/filter_calls_module.Rd

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

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

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

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

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

4 changes: 2 additions & 2 deletions man/srv_nested_tabs.Rd

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

4 changes: 2 additions & 2 deletions man/srv_tabs_with_filters.Rd

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

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

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

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

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

5 changes: 2 additions & 3 deletions man/ui_nested_tabs.Rd

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

5 changes: 2 additions & 3 deletions man/ui_tabs_with_filters.Rd

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

15 changes: 15 additions & 0 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,18 @@ testthat::test_that("init data accepts a list of TealDatasetConnector object", {
NA
)
})

testthat::test_that("init modules accepts a teal_modules object", {
mods <- modules(example_module(), example_module())
testthat::expect_error(init(data = iris, modules = mods), NA)
})

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

testthat::test_that("init modules accepts a teal_module object", {
mods <- example_module()
testthat::expect_error(init(data = iris, modules = mods), NA)
})
10 changes: 5 additions & 5 deletions vignettes/adding-support-for-reporting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(teal_example_module())
modules = teal_example_module()
)

if (interactive()) shinyApp(app$ui, app$server)
Expand Down Expand Up @@ -97,7 +97,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module_with_reporting())
modules = example_module_with_reporting()
)

if (interactive()) shinyApp(app$ui, app$server)
Expand Down Expand Up @@ -148,7 +148,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module_with_reporting())
modules = example_module_with_reporting()
)

if (interactive()) shinyApp(app$ui, app$server)
Expand Down Expand Up @@ -206,7 +206,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module_with_reporting())
modules = example_module_with_reporting()
)

if (interactive()) shinyApp(app$ui, app$server)
Expand Down Expand Up @@ -327,7 +327,7 @@ app <- init(
dataset("IRIS", iris, code = "data(iris); IRIS <- iris"),
check = FALSE
),
modules = modules(
modules = list(
example_reporter_module(label = "with Reporter"),
example_module(label = "without Reporter")
),
Expand Down
14 changes: 6 additions & 8 deletions vignettes/creating-custom-modules.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,12 @@ app <- init(
dataset("IRIS", iris, code = "IRIS <- iris"),
check = TRUE
),
modules = modules(
tm_histogram_example(
label = "Simple Module",
histogram_var = data_extract_spec(
dataname = "IRIS",
select = select_spec(
choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
)
modules = tm_histogram_example(
label = "Simple Module",
histogram_var = data_extract_spec(
dataname = "IRIS",
select = select_spec(
choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
)
)
),
Expand Down
2 changes: 1 addition & 1 deletion vignettes/including-adam-data-in-teal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ example_data <- cdisc_data(

app <- init(
data = example_data,
modules = modules(example_module())
modules = example_module()
)

if (interactive()) {
Expand Down
4 changes: 2 additions & 2 deletions vignettes/including-general-data-in-teal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ app <- init(
dataset("IRIS", iris, code = "IRIS <- iris"),
dataset("CARS", mtcars, code = "CARS <- mtcars")
),
modules = modules(example_module())
modules = example_module()
)

if (interactive()) {
Expand Down Expand Up @@ -69,7 +69,7 @@ app <- init(
fun_dataset_connector("PETS", fun = pet_generator, keys = "ID")
) %>%
mutate_join_keys("PERSON", "PETS", c("ID" = "PERSON_ID")),
modules = modules(example_module())
modules = example_module()
)

if (interactive()) {
Expand Down
4 changes: 1 addition & 3 deletions vignettes/including-mae-data-in-teal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ mae_d <- dataset("MAE", miniACC, metadata = list(type = "example"))

app <- init(
data = teal_data(mae_d),
modules = modules(
example_module()
)
modules = example_module()
)

if (interactive()) {
Expand Down
4 changes: 2 additions & 2 deletions vignettes/preprocessing-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cs_arm <- choices_selected(c("ACTARMCD", "ARMCD"), "ACTARMCD")

app <- init(
data = cdisc_data(cdisc_dataset("ADSL", adsl), code = get_code(file = "app.R")),
modules = modules(example_module())
modules = example_module()
)

shinyApp(app$ui, app$server)
Expand Down Expand Up @@ -72,7 +72,7 @@ x <- init(
code = get_code("app.R", exclude_comments = TRUE, read_sources = TRUE),
check = TRUE
),
modules = modules(example_module()),
modules = example_module(),
header = "Simple app with preprocessing",
footer = tags$p(class = "text-muted", "Source: agile-R website")
)
Expand Down
4 changes: 2 additions & 2 deletions vignettes/teal-bs-themes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module(), example_module()),
modules = list(example_module(), example_module()),
header = "My first teal application"
)

Expand All @@ -142,7 +142,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module(), example_module()),
modules = list(example_module(), example_module()),
header = "My first teal application"
)

Expand Down
2 changes: 1 addition & 1 deletion vignettes/teal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ app <- init(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
),
modules = modules(example_module()),
modules = example_module(),
header = "My first teal application"
)

Expand Down