From b2ab6365cdf87635e1230337e0345ba3a4450748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Mon, 10 Feb 2025 12:49:28 +0100 Subject: [PATCH 1/4] Add new test combining choices_selected and value_choices --- tests/testthat/test-choices_selected.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 4cf40b41..45f5e8dc 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -70,6 +70,12 @@ testthat::test_that("choices_selected throws error when selected is not found in choices_selected(choices = c("a"), selected = c("c", "b")), "Must be a subset of \\{'a'\\}" ) + testthat::expect_error( + choices_selected( + value_choices("ADTTE", "PARAMCD", "PARAM"), + "OS" + ) + ) }) testthat::test_that("delayed_choices select the desired choices", { From 137ea045254b93c9e4e93b4c38e2149cbe5a90f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Tue, 11 Feb 2025 11:53:18 +0100 Subject: [PATCH 2/4] Stop if selected is not in choices --- R/choices_selected.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/choices_selected.R b/R/choices_selected.R index a12a5d3c..e39c89a2 100644 --- a/R/choices_selected.R +++ b/R/choices_selected.R @@ -152,6 +152,10 @@ choices_selected <- function(choices, } if (inherits(choices, "delayed_data")) { + + if (is.character(selected) && (!all(selected %in% choices$var_choices) || !all(selected %in% choices$var_label))) { + stop("Selected, '", selected, "' is not in the available choices.") + } return( structure( list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed), From 3e95f66234085f372a8a3cdaa5fa2ee765b22b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Tue, 11 Feb 2025 12:12:21 +0100 Subject: [PATCH 3/4] Do not raise error on delayed choices --- R/choices_selected.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/choices_selected.R b/R/choices_selected.R index e39c89a2..be0137dd 100644 --- a/R/choices_selected.R +++ b/R/choices_selected.R @@ -153,8 +153,10 @@ choices_selected <- function(choices, if (inherits(choices, "delayed_data")) { - if (is.character(selected) && (!all(selected %in% choices$var_choices) || !all(selected %in% choices$var_label))) { - stop("Selected, '", selected, "' is not in the available choices.") + if (is.character(selected) && !inherits(choices, "delayed_variable_choices")) { + if (!all(selected %in% choices$var_choices) || !all(selected %in% choices$var_label)) { + stop("Selected, '", selected, "' is not in the available choices.") + } } return( structure( From c33e92d2cfea7a38f861c992ee9becfad9fc0878 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2025 11:17:05 +0000 Subject: [PATCH 4/4] [skip style] [skip vbump] Restyle files --- R/choices_selected.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/choices_selected.R b/R/choices_selected.R index be0137dd..66cf88e8 100644 --- a/R/choices_selected.R +++ b/R/choices_selected.R @@ -152,7 +152,6 @@ choices_selected <- function(choices, } if (inherits(choices, "delayed_data")) { - if (is.character(selected) && !inherits(choices, "delayed_variable_choices")) { if (!all(selected %in% choices$var_choices) || !all(selected %in% choices$var_label)) { stop("Selected, '", selected, "' is not in the available choices.")