Skip to content

Commit

Permalink
unify naming convention transformers->transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Nov 11, 2024
1 parent cabf9f2 commit 350d990
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ init <- function(data,
}

is_modules_ok <- check_modules_datanames(modules, names(data))
if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) {
if (!isTRUE(is_modules_ok) && length(unlist(extract_transforms(modules))) == 0) {
warning(is_modules_ok, call. = FALSE)
}

Expand Down
24 changes: 12 additions & 12 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,22 @@ modules <- function(..., label = "root") {
#' @param is_root (`logical(1)`) Whether this is the root node of the tree. Only used in
#' format.teal_modules(). Determines whether to show "TEAL ROOT" header
#' @param what (`character`) Specifies which metadata to display.
#' Possible values: "datasets", "properties", "ui_args", "server_args", "transformers"
#' Possible values: "datasets", "properties", "ui_args", "server_args", "transforms"
#' @examples
#' mod <- module(
#' label = "My Custom Module",
#' server = function(id, data, ...) {},
#' ui = function(id, ...) {},
#' datanames = c("ADSL", "ADTTE"),
#' transformers = list(),
#' transforms = list(),
#' ui_args = list(a = 1, b = "b"),
#' server_args = list(x = 5, y = list(p = 1))
#' )
#' cat(format(mod))
#' @export
format.teal_module <- function(
x, indent = 0, is_last = FALSE, parent_prefix = "",
what = c("datasets", "properties", "ui_args", "server_args", "transformers"), ...) {
what = c("datasets", "properties", "ui_args", "server_args", "transforms"), ...) {
empty_text <- ""
branch <- if (is_last) "L-" else "|-"
current_prefix <- paste0(parent_prefix, branch, " ")
Expand Down Expand Up @@ -381,8 +381,8 @@ format.teal_module <- function(
bookmarkable <- isTRUE(attr(x, "teal_bookmarkable"))
reportable <- "reporter" %in% names(formals(x$server))

transformers <- if (length(x$transformers) > 0) {
paste(sapply(x$transformers, function(t) attr(t, "label")), collapse = ", ")
transforms <- if (length(x$transforms) > 0) {
paste(sapply(x$transforms, function(t) attr(t, "label")), collapse = ", ")
} else {
empty_text
}
Expand Down Expand Up @@ -417,10 +417,10 @@ format.teal_module <- function(
content_prefix, "|- ", crayon::green("Server Arguments : "), server_args_formatted, "\n"
)
}
if ("transformers" %in% what) {
if ("transforms" %in% what) {
output <- paste0(
output,
content_prefix, "L- ", crayon::magenta("Transformers : "), transformers, "\n"
content_prefix, "L- ", crayon::magenta("Transforms : "), transforms, "\n"
)
}

Expand All @@ -431,14 +431,14 @@ format.teal_module <- function(
#' @examples
#' custom_module <- function(
#' label = "label", ui_args = NULL, server_args = NULL,
#' datanames = "all", transformers = list(), bk = FALSE) {
#' datanames = "all", transforms = list(), bk = FALSE) {
#' ans <- module(
#' label,
#' server = function(id, data, ...) {},
#' ui = function(id, ...) {
#' },
#' datanames = datanames,
#' transformers = transformers,
#' transforms = transforms,
#' ui_args = ui_args,
#' server_args = server_args
#' )
Expand Down Expand Up @@ -475,7 +475,7 @@ format.teal_module <- function(
#' cache = TRUE,
#' debounce = 1000
#' ),
#' transformers = list(dummy_transformer),
#' transforms = list(dummy_transformer),
#' bk = TRUE
#' ),
#' modules(
Expand All @@ -493,7 +493,7 @@ format.teal_module <- function(
#' render_type = "svg",
#' cache_plots = TRUE
#' ),
#' transformers = list(dummy_transformer, plot_transformer),
#' transforms = list(dummy_transformer, plot_transformer),
#' bk = TRUE
#' ),
#' modules(
Expand Down Expand Up @@ -525,7 +525,7 @@ format.teal_module <- function(
#' )
#'
#' cat(format(complete_modules))
#' cat(format(complete_modules, what = c("ui_args", "server_args", "transformers")))
#' cat(format(complete_modules, what = c("ui_args", "server_args", "transforms")))
#' @export
format.teal_modules <- function(x, indent = 0, is_root = TRUE, is_last = FALSE, parent_prefix = "", ...) {
if (is_root) {
Expand Down
4 changes: 2 additions & 2 deletions R/teal_transform_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#'
#'
#' @examples
#' data_transformers <- list(
#' data_transforms <- list(
#' teal_transform_module(
#' label = "Static transform for iris",
#' datanames = "iris",
Expand Down Expand Up @@ -101,7 +101,7 @@
#'
#' app <- init(
#' data = teal_data(iris = iris),
#' modules = example_module(transforms = data_transformers)
#' modules = example_module(transforms = data_transforms)
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
Expand Down
16 changes: 8 additions & 8 deletions man/teal_modules.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/teal_transform_module.Rd

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

8 changes: 4 additions & 4 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ testthat::test_that("init throws when an empty `data` is used", {
})

testthat::test_that(
"init throws warning when datanames in modules incompatible w/ datanames in data and there is no transformers",
"init throws warning when datanames in modules incompatible w/ datanames in data and there is no transforms",
{
testthat::expect_warning(
init(
Expand All @@ -70,7 +70,7 @@ testthat::test_that(
)

testthat::test_that(
"init throws warning when datanames in modules incompatible w/ datanames in data and there is no transformers",
"init throws warning when datanames in modules incompatible w/ datanames in data and there is no transforms",
{
testthat::expect_warning(
init(
Expand All @@ -83,15 +83,15 @@ testthat::test_that(
)

testthat::test_that(
"init does not throw warning when datanames in modules incompatible w/ datanames in data and there are transformers",
"init does not throw warning when datanames in modules incompatible w/ datanames in data and there are transforms",
{
testthat::expect_no_warning(
init(
data = teal.data::teal_data(mtcars = mtcars),
modules = list(
example_module(
datanames = "iris",
transformers = list(
transforms = list(
teal_transform_module(
ui = function(id) NULL,
server = function(id, data) {
Expand Down
Loading

0 comments on commit 350d990

Please sign in to comment.