diff --git a/DESCRIPTION b/DESCRIPTION index 9e700aa3..20bbcfa9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,7 @@ Imports: checkmate, ggplot2, graphics, + grDevices, htmltools, lifecycle, methods, diff --git a/NEWS.md b/NEWS.md index a1cd34f0..2942a6b4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # teal.widgets 0.4.0.9001 +### Miscellaneous + +* Documentation enhancements - code formatting package names and R objects. +* Add `grDevices` to Imports. + # teal.widgets 0.4.0 ### Bug fixes diff --git a/R/basic_table_args.R b/R/basic_table_args.R index e3d28394..44ef3779 100644 --- a/R/basic_table_args.R +++ b/R/basic_table_args.R @@ -46,7 +46,7 @@ basic_table_args <- function(...) { #' module creator setup for [rtables::basic_table()] of a specific table. #' Created with the [basic_table_args()] function. The `NULL` value is supported. #' @param app_default (`basic_table_args`)\cr -#' teal option variable. The `NULL` value is supported. +#' Application level setting. Can be `NULL`. #' #' @return `basic_table_args` object. #' @details diff --git a/R/ggplot2_args.R b/R/ggplot2_args.R index 62b6388e..dfb2e837 100644 --- a/R/ggplot2_args.R +++ b/R/ggplot2_args.R @@ -61,7 +61,7 @@ ggplot2_args <- function(labs = list(), theme = list()) { #' module creator setup for theme and labs in the specific plot. #' Created with the [ggplot2_args()] function. The `NULL` value is supported. #' @param app_default (`ggplot2_args`)\cr -#' teal option variable. The `NULL` value is supported. +#' Application level setting. Can be `NULL`. #' #' @return `ggplot2_args` object. #' diff --git a/R/optionalInput.R b/R/optionalInput.R index 8881dc03..10b4fd6b 100644 --- a/R/optionalInput.R +++ b/R/optionalInput.R @@ -421,12 +421,12 @@ optionalSliderInput <- function(inputId, label, min, max, value, label_help = NU } } -#' For teal modules we parameterize an \code{optionalSliderInput} with one argument +#' For `teal` modules we parameterize an \code{optionalSliderInput} with one argument #' \code{value_min_max} #' #' @description `r lifecycle::badge("stable")` -#' The [optionalSliderInput()] function needs three arguments to decided -#' whether to hide the `sliderInput` widget or not. For teal modules we specify an +#' The [optionalSliderInput()] function needs three arguments to determine +#' whether to hide the `sliderInput` widget or not. For `teal` modules we specify an #' optional slider input with one argument here called `value_min_max`. #' #' @inheritParams optionalSliderInput @@ -443,20 +443,26 @@ optionalSliderInput <- function(inputId, label, min, max, value, label_help = NU #' optionalSliderInputValMinMax("a", "b", 1) #' optionalSliderInputValMinMax("a", "b", c(3, 1, 5)) optionalSliderInputValMinMax <- function(inputId, label, value_min_max, label_help = NULL, ...) { # nolint + checkmate::assert( + checkmate::check_numeric( + value_min_max, + finite = TRUE, + len = 3 + ), + checkmate::check_numeric( + value_min_max, + finite = TRUE, + len = 1 + ) + ) x <- value_min_max - if (!is.numeric(x)) stop("value_min_max is expected to be numeric") - vals <- if (length(x) == 3) { - if (any(diff(x[c(2, 1, 3)]) < 0)) { - stop(paste("value_min_max is expected to be (value, min, max) where min <= value <= max")) - } + checkmate::assert_number(x[1], lower = x[2], upper = x[3], .var.name = "value_min_max") list(value = x[1], min = x[2], max = x[3]) } else if (length(x) == 1) { list(value = x, min = NA_real_, max = NA_real_) - } else { - stop(paste("value_min_max is expected to be of length 1 (value) or of length 3 (value, min, max)")) } slider <- optionalSliderInput(inputId, label, vals$min, vals$max, vals$value, ...) diff --git a/R/standard_layout.R b/R/standard_layout.R index 33f9cb64..cd004e96 100644 --- a/R/standard_layout.R +++ b/R/standard_layout.R @@ -2,7 +2,7 @@ #' the left #' #' @description `r lifecycle::badge("stable")` -#' This is the layout used for the teal modules in the `beam` package +#' This is the layout used by the `teal` modules. #' #' @param output (`shiny.tag`)\cr #' object with the output element (table, plot, listing) such as for example returned @@ -26,18 +26,10 @@ standard_layout <- function(output, pre_output = NULL, post_output = NULL) { # checking arguments - if (!inherits(output, c("shiny.tag", "shiny.tag.list", "html"))) { - stop("output is supposed to be of class shiny.tag or shiny.tag.list") - } - for (name in names(l <- list( - "encoding" = encoding, - "pre_output" = pre_output, - "post_output" = post_output - ))) { - if (!is.null(l[[name]]) && !inherits(l[[name]], c("shiny.tag", "shiny.tag.list", "html"))) { - stop(paste(name, "is supposed to be NULL, shiny.tag or shiny.tag.list.")) - } - } + checkmate::assert_multi_class(output, c("shiny.tag", "shiny.tag.list", "html")) + checkmate::assert_multi_class(encoding, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) + checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE) # if encoding=NULL then forms is placed below output diff --git a/R/teal.widgets-package.R b/R/teal.widgets-package.R index 0ba90998..50f15ac1 100644 --- a/R/teal.widgets-package.R +++ b/R/teal.widgets-package.R @@ -1,7 +1,7 @@ -#' teal.widgets: Custom widgets for teal applications +#' `teal.widgets`: Custom widgets for `teal` applications #' #' The `teal.widgets` package contains functionalities that can be used -#' for teal module development. The Package is dedicated to allow developers to extend modules +#' for `teal` module development. The package is dedicated to allow developers to extend module #' functionality by additional inputs and output controls. #' #' @keywords internal diff --git a/R/verbatim_popup.R b/R/verbatim_popup.R index fd977623..9566d9e7 100644 --- a/R/verbatim_popup.R +++ b/R/verbatim_popup.R @@ -30,8 +30,7 @@ verbatim_popup_ui <- function(id, button_label, type = c("button", "link"), ...) ui_function <- switch(match.arg(type), "button" = shiny::actionButton, - "link" = shiny::actionLink, - stop("Argument 'type' should be 'button' or 'link'") + "link" = shiny::actionLink ) ns <- shiny::NS(id) diff --git a/man/optionalSliderInputValMinMax.Rd b/man/optionalSliderInputValMinMax.Rd index da06eb01..5f6aef52 100644 --- a/man/optionalSliderInputValMinMax.Rd +++ b/man/optionalSliderInputValMinMax.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/optionalInput.R \name{optionalSliderInputValMinMax} \alias{optionalSliderInputValMinMax} -\title{For teal modules we parameterize an \code{optionalSliderInput} with one argument +\title{For \code{teal} modules we parameterize an \code{optionalSliderInput} with one argument \code{value_min_max}} \usage{ optionalSliderInputValMinMax( @@ -30,8 +30,8 @@ an object of class \code{shiny.tag}. E.g. an object returned by \code{\link[shin } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -The \code{\link[=optionalSliderInput]{optionalSliderInput()}} function needs three arguments to decided -whether to hide the \code{sliderInput} widget or not. For teal modules we specify an +The \code{\link[=optionalSliderInput]{optionalSliderInput()}} function needs three arguments to determine +whether to hide the \code{sliderInput} widget or not. For \code{teal} modules we specify an optional slider input with one argument here called \code{value_min_max}. } \examples{ diff --git a/man/resolve_basic_table_args.Rd b/man/resolve_basic_table_args.Rd index 22b93d9f..22a8ff55 100644 --- a/man/resolve_basic_table_args.Rd +++ b/man/resolve_basic_table_args.Rd @@ -25,7 +25,7 @@ module creator setup for \code{\link[rtables:basic_table]{rtables::basic_table() Created with the \code{\link[=basic_table_args]{basic_table_args()}} function. The \code{NULL} value is supported.} \item{app_default}{(\code{basic_table_args})\cr -teal option variable. The \code{NULL} value is supported.} +Application level setting. Can be \code{NULL}.} } \value{ \code{basic_table_args} object. diff --git a/man/resolve_ggplot2_args.Rd b/man/resolve_ggplot2_args.Rd index edbe163e..6806b8f8 100644 --- a/man/resolve_ggplot2_args.Rd +++ b/man/resolve_ggplot2_args.Rd @@ -25,7 +25,7 @@ module creator setup for theme and labs in the specific plot. Created with the \code{\link[=ggplot2_args]{ggplot2_args()}} function. The \code{NULL} value is supported.} \item{app_default}{(\code{ggplot2_args})\cr -teal option variable. The \code{NULL} value is supported.} +Application level setting. Can be \code{NULL}.} } \value{ \code{ggplot2_args} object. diff --git a/man/standard_layout.Rd b/man/standard_layout.Rd index da32d465..33f8437a 100644 --- a/man/standard_layout.Rd +++ b/man/standard_layout.Rd @@ -36,5 +36,5 @@ an object of class \code{shiny.tag} with the UI code. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} -This is the layout used for the teal modules in the \code{beam} package +This is the layout used by the \code{teal} modules. } diff --git a/man/teal.widgets-package.Rd b/man/teal.widgets-package.Rd index ed7ccf8c..7fe81805 100644 --- a/man/teal.widgets-package.Rd +++ b/man/teal.widgets-package.Rd @@ -4,10 +4,10 @@ \name{teal.widgets-package} \alias{teal.widgets} \alias{teal.widgets-package} -\title{teal.widgets: Custom widgets for teal applications} +\title{\code{teal.widgets}: Custom widgets for \code{teal} applications} \description{ The \code{teal.widgets} package contains functionalities that can be used -for teal module development. The Package is dedicated to allow developers to extend modules +for \code{teal} module development. The package is dedicated to allow developers to extend module functionality by additional inputs and output controls. } \author{ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png index 8d536f42..505d0f89 100644 Binary files a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-download_menu.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png index 26d11b9b..5fec9158 100644 Binary files a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-hidden.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png index 764aa5d5..b7664369 100644 Binary files a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-resize_menu.png differ diff --git a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png index e7052a37..7d8d88bb 100644 Binary files a/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png and b/tests/testthat/_snaps/app_pws_ui/plot_with_settings_ui/pws-visible.png differ diff --git a/tests/testthat/helpers-with-settings.R b/tests/testthat/helpers-with-settings.R index 0418eb63..6def17aa 100644 --- a/tests/testthat/helpers-with-settings.R +++ b/tests/testthat/helpers-with-settings.R @@ -86,11 +86,11 @@ app_pws <- function() { #' @keywords internal is_draw <- function(plot_fun) { checkmate::assert_function(plot_fun) - graphics.off() # close any current graphics devices - cdev <- dev.cur() + grDevices::graphics.off() # close any current graphics devices + cdev <- grDevices::dev.cur() plot_fun() - if (cdev != dev.cur()) { - on.exit(dev.off()) + if (cdev != grDevices::dev.cur()) { + on.exit(grDevices::dev.off()) return(TRUE) } return(FALSE) diff --git a/tests/testthat/test-plot_with_settings_ui.R b/tests/testthat/test-plot_with_settings_ui.R index a6222f13..5cd4dc61 100644 --- a/tests/testthat/test-plot_with_settings_ui.R +++ b/tests/testthat/test-plot_with_settings_ui.R @@ -1,8 +1,8 @@ -testthat::test_that("type_download_ui returns shiny.tag", { +testthat::test_that("type_download_ui returns `shiny.tag`", { testthat::expect_s3_class(type_download_ui("STH"), "shiny.tag") }) -testthat::test_that("plot_with_settings_ui returns shiny.tag.list", { +testthat::test_that("plot_with_settings_ui returns `shiny.tag.list`", { testthat::expect_s3_class(plot_with_settings_ui("STH"), "shiny.tag.list") }) diff --git a/tests/testthat/test-standard_layout.R b/tests/testthat/test-standard_layout.R index 706152af..6cd3e1b2 100644 --- a/tests/testthat/test-standard_layout.R +++ b/tests/testthat/test-standard_layout.R @@ -4,25 +4,28 @@ testthat::test_that("Input validation", { testthat::expect_error( standard_layout(NULL), - regexp = "output is supposed to be of class shiny.tag or shiny.tag.list" + regexp = "Assertion on 'output' failed" ) - testthat::expect_error(standard_layout(1), regexp = "output is supposed to be of class shiny.tag or shiny.tag.list") + testthat::expect_error( + standard_layout(1), + regexp = "Assertion on 'output' failed" + ) testthat::expect_error(standard_layout( output = tags$div(), encoding = 1 - ), regexp = "encoding is supposed to be NULL, shiny.tag or shiny.tag.list.") + ), regexp = "Assertion on 'encoding' failed") testthat::expect_error(standard_layout( output = tags$div(), pre_output = 1 - ), regexp = "pre_output is supposed to be NULL, shiny.tag or shiny.tag.list.") + ), regexp = "Assertion on 'pre_output' failed") testthat::expect_error(standard_layout( output = tags$div(), post_output = 1 - ), regexp = "post_output is supposed to be NULL, shiny.tag or shiny.tag.list.") + ), regexp = "Assertion on 'post_output' failed") }) # Result ----