Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
Merge commit '8c143f108778c5a03364747d5f6b6aaac5a252d7'

#Conflicts:
#	tests/testthat/test-module_teal.R
  • Loading branch information
llrs-roche committed Nov 22, 2024
2 parents 7e8f6e5 + 8c143f1 commit a738d20
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 47 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
r-cmd-non-cran:
name: R CMD Check (non-CRAN) 🧬
uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main
Expand Down Expand Up @@ -79,6 +82,9 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
coverage:
name: Coverage 📔
uses: insightsengineering/r.pkg.template/.github/workflows/test-coverage.yaml@main
Expand All @@ -95,6 +101,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
linter:
if: github.event_name != 'push'
name: SuperLinter 🦸‍♀️
Expand All @@ -114,6 +122,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
gitleaks:
name: gitleaks 💧
uses: insightsengineering/r.pkg.template/.github/workflows/gitleaks.yaml@main
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
8 changes: 8 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
validation:
name: R Package Validation report 📃
needs: release
Expand All @@ -39,6 +41,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
release:
name: Create release 🎉
uses: insightsengineering/r.pkg.template/.github/workflows/release.yaml@main
Expand Down Expand Up @@ -71,6 +75,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
coverage:
name: Coverage 📔
needs: [release, docs]
Expand All @@ -88,6 +94,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
wasm:
name: Build WASM packages 🧑‍🏭
needs: release
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/scheduled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
rhub:
if: >
github.event_name == 'schedule' || (
Expand All @@ -80,3 +82,5 @@ jobs:
insightsengineering/teal.logger
insightsengineering/teal.reporter
insightsengineering/teal.widgets
insightsengineering/rtables
insightsengineering/rtables.officer
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: teal
Title: Exploratory Web Apps for Analyzing Clinical Trials Data
Version: 0.15.2.9086
Date: 2024-11-15
Version: 0.15.2.9089
Date: 2024-11-20
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9533-457X")),
Expand Down Expand Up @@ -38,7 +38,7 @@ Depends:
R (>= 4.0),
shiny (>= 1.8.1),
teal.data (>= 0.6.0.9017),
teal.slice (>= 0.5.1.9009)
teal.slice (>= 0.5.1.9015)
Imports:
checkmate (>= 2.1.0),
crayon,
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal 0.15.2.9086
# teal 0.15.2.9089

### New features

Expand All @@ -8,6 +8,7 @@
* Possibility to download lockfile to restore app session for reproducibility. #479
* Introduced a function `set_datanames()` to change a `datanames` of the `teal_module`.
* Datasets which name starts with `.` are ignored when `module`'s `datanames` is set as `"all"`.
* Added warning when reserved `datanames`, such as `all` and `.raw_data` are being used.

### Breaking changes

Expand Down
79 changes: 65 additions & 14 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,58 @@ check_modules_datanames <- function(modules, datanames) {
}

#' @rdname check_modules_datanames
check_modules_datanames_html <- function(modules,
datanames) {
check_reserved_datanames <- function(datanames) {
reserved_datanames <- datanames[datanames %in% c("all", ".raw_data")]
if (length(reserved_datanames) == 0L) {
return(NULL)
}

tags$span(
to_html_code_list(reserved_datanames),
sprintf(
"%s reserved for internal use. Please avoid using %s as %s.",
pluralize(reserved_datanames, "is", "are"),
pluralize(reserved_datanames, "it", "them"),
pluralize(reserved_datanames, "a dataset name", "dataset names")
)
)
}

#' @rdname check_modules_datanames
check_modules_datanames_html <- function(modules, datanames) {
check_datanames <- check_modules_datanames_recursive(modules, datanames)
show_module_info <- inherits(modules, "teal_modules") # used in two contexts - module and app

reserved_datanames <- check_reserved_datanames(datanames)

if (!length(check_datanames)) {
return(TRUE)
out <- if (is.null(reserved_datanames)) {
TRUE
} else {
shiny::tagList(reserved_datanames)
}
return(out)
}
shiny::tagList(
reserved_datanames,
lapply(
check_datanames,
function(mod) {
tagList(
tags$span(
tags$span(if (length(mod$missing_datanames) == 1) "Dataset" else "Datasets"),
tags$span(pluralize(mod$missing_datanames, "Dataset")),
to_html_code_list(mod$missing_datanames),
tags$span(
paste0(
if (length(mod$missing_datanames) > 1) "are missing" else "is missing",
if (show_module_info) sprintf(" for module '%s'.", mod$label) else "."
sprintf(
"%s missing%s.",
pluralize(mod$missing_datanames, "is", "are"),
if (show_module_info) sprintf(" for module '%s'", mod$label) else ""
)
)
),
if (length(datanames) >= 1) {
tagList(
tags$span(if (length(datanames) == 1) "Dataset" else "Datasets"),
tags$span(pluralize(datanames, "Dataset")),
tags$span("available in data:"),
tagList(
tags$span(
Expand Down Expand Up @@ -382,7 +409,7 @@ paste_datanames_character <- function(x,
tagList(
tags$code(x[.ix]),
if (.ix != length(x)) {
tags$span(ifelse(.ix == length(x) - 1, " and ", ", "))
tags$span(if (.ix == length(x) - 1) " and " else ", ")
}
)
})
Expand All @@ -400,17 +427,18 @@ build_datanames_error_message <- function(label = NULL,
tags = list(span = shiny::tags$span, code = shiny::tags$code),
tagList = shiny::tagList) { # nolint: object_name.
tags$span(
tags$span(ifelse(length(extra_datanames) > 1, "Datasets", "Dataset")),
tags$span(pluralize(extra_datanames, "Dataset")),
paste_datanames_character(extra_datanames, tags, tagList),
tags$span(
paste0(
ifelse(length(extra_datanames) > 1, "are missing", "is missing"),
ifelse(is.null(label), ".", sprintf(" for tab '%s'.", label))
sprintf(
"%s missing%s",
pluralize(extra_datanames, "is", "are"),
if (is.null(label)) "" else sprintf(" for tab '%s'", label)
)
),
if (length(datanames) >= 1) {
tagList(
tags$span(ifelse(length(datanames) > 1, "Datasets", "Dataset")),
tags$span(pluralize(datanames, "Dataset")),
tags$span("available in data:"),
tagList(
tags$span(
Expand Down Expand Up @@ -445,3 +473,26 @@ build_datanames_error_message <- function(label = NULL,
}
)
}

#' Pluralize a word depending on the size of the input
#'
#' @param x (`object`) to check length for plural.
#' @param singular (`character`) singular form of the word.
#' @param plural (optional `character`) plural form of the word. If not given an "s"
#' is added to the singular form.
#'
#' @return A `character` that correctly represents the size of the `x` argument.
#' @keywords internal
pluralize <- function(x, singular, plural = NULL) {
checkmate::assert_string(singular)
checkmate::assert_string(plural, null.ok = TRUE)
if (length(x) == 1L) { # Zero length object should use plural form.
singular
} else {
if (is.null(plural)) {
sprintf("%ss", singular)
} else {
plural
}
}
}
3 changes: 3 additions & 0 deletions man/check_modules_datanames.Rd

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

23 changes: 23 additions & 0 deletions man/pluralize.Rd

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

27 changes: 27 additions & 0 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,33 @@ testthat::test_that(
}
)

testthat::describe("init throws warning when datanames in modules has reserved name", {
testthat::it("`all`", {
testthat::expect_warning(
init(
data = teal.data::teal_data(all = mtcars),
modules = list(example_module())
),
"`all` is reserved for internal use\\. Please avoid using it as a dataset name\\."
)
})

testthat::it("`.raw_data` and `all`", {
td <-
testthat::expect_warning(
init(
data = teal.data::teal_data(
all = mtcars,
.raw_data = iris,
join_keys = teal.data::join_keys(teal.data::join_key(".raw_data", "all", "a_key"))
),
modules = list(example_module())
),
"`.raw_data` and `all` are reserved for internal use\\. Please avoid using them as dataset names\\."
)
})
})

testthat::test_that("init throws when dataname in filter incompatible w/ datanames in data", {
testthat::expect_warning(
init(
Expand Down
Loading

0 comments on commit a738d20

Please sign in to comment.