Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/choices_selected.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ 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.")
}
}
Comment on lines +155 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to determine this at this point? If choices are delayed, we can't guess if selected is a subset of the chocies.

return(
structure(
list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed),
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-choices_selected.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Loading