Skip to content

Commit

Permalink
revert export of resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Feb 12, 2024
1 parent ba42e7b commit aff0f35
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 114 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export(merge_datasets)
export(merge_expression_module)
export(merge_expression_srv)
export(no_selected_as_NULL)
export(resolve)
export(resolve_delayed)
export(select_spec)
export(select_spec.default)
Expand Down
70 changes: 13 additions & 57 deletions R/resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,17 @@
#'
#' `r lifecycle::badge("stable")`
#'
#' @note This is an internal function that is used by [resolve_delayed()].
#' All the methods are used internally only.
#'
#' @param x (`delayed_data`) object to resolve.
#' @param datasets (named `list` of `data.frame`) to use in evaluation.
#' @param keys (named `list` of `character`) to be used as the keys for each dataset.
#' The names of this list must be exactly the same as for datasets.
#'
#' @return Resolved object.
#'
#' @examples
#' library(shiny)
#' ADSL <- rADSL
#'
#' attr(ADSL, "keys") <- c("STUDYID", "USUBJID")
#' data_list <- list(ADSL = reactive(ADSL))
#' keys <- list(ADSL = attr(ADSL, "keys"))
#' isolate({
#' # value_choices example
#' v1 <- value_choices("ADSL", "SEX", "SEX")
#' v1
#' resolve(v1, data_list, keys)
#'
#' # variable_choices example
#' v2 <- variable_choices("ADSL", c("BMRKR1", "BMRKR2"))
#' v2
#' resolve(v2, data_list, keys)
#'
#' # data_extract_spec example
#' adsl_filter <- filter_spec(
#' vars = variable_choices("ADSL", "SEX"),
#' sep = "-",
#' choices = value_choices("ADSL", "SEX", "SEX"),
#' selected = "F",
#' multiple = FALSE,
#' label = "Choose endpoint and Censor"
#' )
#'
#' adsl_select <- select_spec(
#' label = "Select variable:",
#' choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")),
#' selected = "BMRKR1",
#' multiple = FALSE,
#' fixed = FALSE
#' )
#'
#' adsl_de <- data_extract_spec(
#' dataname = "ADSL",
#' select = adsl_select,
#' filter = adsl_filter
#' )
#'
#' resolve(adsl_filter, data_list, keys)
#' resolve(adsl_select, data_list, keys)
#' resolve(adsl_de, data_list, keys)
#'
#' # nested list (arm_ref_comp)
#' arm_ref_comp <- list(
#' ARMCD = list(
#' ref = variable_choices("ADSL"),
#' comp = variable_choices("ADSL")
#' )
#' )
#'
#' resolve(arm_ref_comp, data_list, keys)
#' })
#' @export
#' @keywords internal
#'
resolve <- function(x, datasets, keys = NULL) {
checkmate::assert_list(datasets, types = "reactive", min.len = 1, names = "named")
Expand All @@ -79,6 +26,7 @@ resolve <- function(x, datasets, keys = NULL) {
UseMethod("resolve")
}

#' @describeIn resolve Call [variable_choices()] on the delayed `variable_choices` object.
#' @export
resolve.delayed_variable_choices <- function(x, datasets, keys) {
if (is.null(x$key)) {
Expand All @@ -92,6 +40,7 @@ resolve.delayed_variable_choices <- function(x, datasets, keys) {
do.call("variable_choices", x)
}

#' @describeIn resolve Call [value_choices()] on the delayed `value_choices` object.
#' @export
resolve.delayed_value_choices <- function(x, datasets, keys) {
x$data <- datasets[[x$data]]()
Expand All @@ -102,6 +51,7 @@ resolve.delayed_value_choices <- function(x, datasets, keys) {
do.call("value_choices", x)
}

#' @describeIn resolve Call [select_spec()] on the delayed `choices_selected` object.
#' @export
resolve.delayed_choices_selected <- function(x, datasets, keys) {
if (inherits(x$selected, "delayed_data")) {
Expand All @@ -121,6 +71,7 @@ resolve.delayed_choices_selected <- function(x, datasets, keys) {
do.call("choices_selected", x)
}

#' @describeIn resolve Call [select_spec()] on the delayed specification.
#' @export
resolve.delayed_select_spec <- function(x, datasets, keys) {
x$choices <- resolve(x$choices, datasets = datasets, keys)
Expand All @@ -131,6 +82,7 @@ resolve.delayed_select_spec <- function(x, datasets, keys) {
do.call("select_spec", x)
}

#' @describeIn resolve Call [filter_spec()] on the delayed specification.
#' @export
resolve.delayed_filter_spec <- function(x, datasets, keys) {
if (inherits(x$vars_choices, "delayed_data")) {
Expand All @@ -149,6 +101,7 @@ resolve.delayed_filter_spec <- function(x, datasets, keys) {
do.call("filter_spec_internal", x[intersect(names(x), methods::formalArgs(filter_spec_internal))])
}

#' @describeIn resolve Call [data_extract_spec()] on the delayed specification.
#' @export
resolve.delayed_data_extract_spec <- function(x, datasets, keys) {
x$select <- `if`(
Expand All @@ -165,12 +118,15 @@ resolve.delayed_data_extract_spec <- function(x, datasets, keys) {
do.call("data_extract_spec", x)
}

#' @describeIn resolve Iterates over elements of the list and recursively calls
#' `resolve`.
#' @export
resolve.list <- function(x, datasets, keys) {
# If specified explicitly, return it unchanged. Otherwise if delayed, resolve.
lapply(x, resolve, datasets = datasets, keys = keys)
}

#' @describeIn resolve Default method that does nothing and returns `x` itself.
#' @export
resolve.default <- function(x, datasets, keys) {
x
Expand Down
104 changes: 48 additions & 56 deletions man/resolve.Rd

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

0 comments on commit aff0f35

Please sign in to comment.