Skip to content

Commit

Permalink
Merge branch '26_new_chunks@main' into origin/main
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Sep 1, 2022
2 parents 22a020f + 2e0633e commit 414c210
Show file tree
Hide file tree
Showing 67 changed files with 1,848 additions and 2,247 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# teal.modules.clinical 0.8.13.9021

### Breaking changes

* Replaced `chunks` with simpler `Quosure` class.
* Replaced `datasets` argument containing `FilteredData` with the new arguments `data` (list of reactive datasets) and `filter_panel_api` (`FilterPanelAPI`).

### Enhancements

* Updated all test files in `tests/testthat/` to `synthetic_cdisc_data("2022_02_28")`
* Reverted missing data checkbox in `tm_t_summary` (encoding and filtering should be separate).
* Implemented a new widget that allows dragging and dropping to select comparison groups.
Expand All @@ -10,10 +16,12 @@
* Added more descriptive title/labels to `tm_g_ci`.

### Bug fixes

* Fixed bug in `tm_g_barchart_simple` which prevented graph from being shown.
* Fixed broken example for `tm_t_abnormality_by_worst_grade`.

### Miscellaneous

* Added `nestcolor` dependency and replaced deprecated function `tern::color_palette` with `nestcolor::color_palette`

# teal.modules.clinical 0.8.13
Expand Down
3 changes: 2 additions & 1 deletion R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ NULL
#' @param arm_var (`choices_selected` or `data_extract_spec`)\cr
#' object with all available choices
#' and preselected option for variable names that can be used as `arm_var`.
#' It defines the grouping variable(s) in the results table. If there are two elements selected for `arm_var`,
#' It defines the grouping variable(s) in the results table.
#' If there are two elements selected for `arm_var`,
#' second variable will be nested under the first variable.
#' @param arm_ref_comp optional, (`list`)\cr
#' If specified it must be a named list with each element corresponding to
Expand Down
61 changes: 21 additions & 40 deletions R/arm_ref_comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' @param id_ref (`character`) id of reference Treatment input ui element
#' @param id_comp (`character`) id of comparison group input ui element
#' @param id_arm_var (`character`) id of Treatment variable input ui element
#' @param datasets (`FilteredData`) object from the module
#' @param dataname (`character`) dataset name
#' @param data (`reactive` or `data.frame`) dataset used to validate Treatment reference inputs and
#' set `id_ref` input.
#' @param arm_ref_comp (`unknown`) Treatment reference and compare variables provided as a
#' nested list where each Treatment variable corresponds a list specifying the default levels for the
#' reference and comparison treatments.
Expand Down Expand Up @@ -60,30 +60,24 @@ arm_ref_comp_observer <- function(session,
id_ref = "Ref",
id_comp = "Comp",
id_arm_var,
datasets,
dataname = "ADSL",
data,
arm_ref_comp,
module,
on_off = shiny::reactive(TRUE),
input_id = "buckets",
output_id = "arms_buckets") {
if (any(unlist(lapply(arm_ref_comp, lapply, inherits, "delayed_data")))) {
stopifnot(
all(vapply(arm_ref_comp, function(x) identical(sort(names(x)), c("comp", "ref")), logical(1)))
)
# when a delayed object is used for arm_ref_comp, the entire FilteredData
# object must be passed to resolve it
arm_ref_comp <- teal.transform::resolve_delayed(arm_ref_comp, datasets)
}

df <- datasets$get_data(dataname, filtered = FALSE)

check_arm_ref_comp(arm_ref_comp, df, module) ## throws an error if there are issues

# uses observe because observeEvent evaluates only when on_off() is switched
# not necessarily when variables are dropped
output[[output_id]] <- shiny::renderUI({
if (!is.null(on_off()) && on_off()) {
df <- if (shiny::is.reactive(data)) {
data()
} else {
data
}

check_arm_ref_comp(arm_ref_comp, df, module) ## throws an error if there are issues

arm_var <- input[[id_arm_var]]

# validations here don't produce nice UI message (it's observe and not render output) but it prevent red errors
Expand All @@ -97,7 +91,6 @@ arm_ref_comp_observer <- function(session,
} else {
unique(arm)
}

default_settings <- arm_ref_comp[[arm_var]]

if (is.null(default_settings)) {
Expand Down Expand Up @@ -150,29 +143,17 @@ check_arm_ref_comp <- function(x, df_to_check, module) {
}


Map(function(xi, var) {
if (!is.list(xi)) {
stop(
msg, "definition for Treatment variable ",
var, " list element needs to be lists with ref and comp elements"
)
}

rc <- names(xi)
if (is.null(rc) || !identical(sort(rc), c("comp", "ref"))) {
stop(msg, "definition for Treatment variable ", var, " nested list needs to have the elements ref and comp")
}


arm_levels <- unlist(xi)

if (!all(arm_levels %in% df_to_check[[var]])) {
stop(
msg, "definition for Treatment variable ",
var, " refers to treatment levels that do not exist in the data"
)
Map(
x, vars,
f = function(xi, var) {
if (!checkmate::check_list(xi) || !setequal(names(xi), c("comp", "ref"))) {
stop(
msg, "definition for Treatment variable ",
var, " list element needs to be lists with ref and comp elements"
)
}
}
}, x, vars)
)
}

invisible(TRUE)
Expand Down
Loading

0 comments on commit 414c210

Please sign in to comment.