From 4229578420f2ac755f65806b0b08df3951f7dbd2 Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Wed, 3 Jul 2024 15:48:08 +0530 Subject: [PATCH] updating get_choices function. (#282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extension to https://github.com/insightsengineering/teal.osprey/pull/276 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com> --- DESCRIPTION | 2 +- R/utils.R | 15 ++++++++++++++- man/get_choices.Rd | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 321b6837..a0ac332b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -77,4 +77,4 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/R/utils.R b/R/utils.R index a8fec2b8..215cc104 100644 --- a/R/utils.R +++ b/R/utils.R @@ -87,6 +87,8 @@ report_card_template_goshawk <- function(title, #' #' This function returns choices based on the class of the input. #' If the input is of class `delayed_data`, it returns the `subset` of the input. +#' If `subset` is NULL and the input contains `var_label` and `var_choices`, +#' it throws an error prompting to resolve delayed inputs. #' Otherwise, it returns the input as is. #' #' @param choices An object that contains choices. @@ -94,7 +96,18 @@ report_card_template_goshawk <- function(title, #' @keywords internal get_choices <- function(choices) { if (inherits(choices, "delayed_data")) { - choices$subset + if (is.null(choices$subset)) { + if (!is.null(choices$var_label) && !is.null(choices$var_choices)) { + stop( + "Resolve delayed inputs by evaluating the code within the provided datasets. + Check ?teal.transform::resolve_delayed for more information." + ) + } else { + stop("Subset is NULL and necessary fields are missing.") + } + } else { + choices$subset + } } else { choices } diff --git a/man/get_choices.Rd b/man/get_choices.Rd index 56cd5af1..a4e7229e 100644 --- a/man/get_choices.Rd +++ b/man/get_choices.Rd @@ -15,6 +15,8 @@ A vector of choices. \description{ This function returns choices based on the class of the input. If the input is of class \code{delayed_data}, it returns the \code{subset} of the input. +If \code{subset} is NULL and the input contains \code{var_label} and \code{var_choices}, +it throws an error prompting to resolve delayed inputs. Otherwise, it returns the input as is. } \keyword{internal}