-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
229 delayed_choices
as separate funcitons
#232
Merged
gogonzo
merged 20 commits into
insightsengineering:main
from
chlebowa:229_delayed_choices_separate@main
Jan 9, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
76022af
replace function all_choices with delayed_choices
chlebowa 45a6f7d
replace use of all_choices with use of delayed_choices; adjust choice…
chlebowa b63e9a1
amend unit tests
chlebowa 3f3305b
amend documentation
chlebowa 268e3d7
amend NEWS
chlebowa 9e293ad
replace delayed_choices with separate functions
chlebowa fcc5e6c
adjust uses of delayed_choices functions
chlebowa 7034a19
amend documentation
chlebowa 1bfe744
amend unit tests
chlebowa 11d1f42
amend NEWS
chlebowa c1f1791
fix one example
chlebowa 9933e15
tweak syntax
chlebowa 7bde9ff
add first_choice and last_choice to pkgdown reference
chlebowa 8365bbf
fix typo
chlebowa f1634f5
Update tests/testthat/test-delayed_choices.R
chlebowa 22961ad
remove explicit return statements
chlebowa 8153968
Revert "Update tests/testthat/test-delayed_choices.R"
chlebowa 5993de1
fix typo
chlebowa e4e5f00
remove Reduce pattern
chlebowa 9990e36
fix typo in NEWS
chlebowa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#' Bare constructor for `delayed_choices` object | ||
#' | ||
#' @description | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' Special S3 structures that delay selection of possible choices in a | ||
#' `filter_spec`, `select_spec` or `choices_selected` object. | ||
#' | ||
#' @return | ||
#' Object of class `delayed_choices`, which is a function that returns | ||
#' the appropriate subset of its argument. The `all_choices` structure | ||
#' also has an additional class for internal use. | ||
#' | ||
#' @examples | ||
#' # These pairs of structures represent semantically identical specifications: | ||
#' choices_selected(choices = letters, selected = letters) | ||
#' choices_selected(choices = letters, selected = all_choices()) | ||
#' | ||
#' choices_selected(choices = letters, selected = letters[1]) | ||
#' choices_selected(choices = letters, selected = first_choice()) | ||
#' | ||
#' filter_spec( | ||
#' vars = c("selected_variable"), | ||
#' choices = c("value1", "value2", "value3"), | ||
#' selected = "value3" | ||
#' ) | ||
#' filter_spec( | ||
#' vars = c("selected_variable"), | ||
#' choices = c("value1", "value2", "value3"), | ||
#' selected = last_choice() | ||
#' ) | ||
#' | ||
#' @name delayed_choices | ||
|
||
#' @export | ||
#' @rdname delayed_choices | ||
all_choices <- function() { | ||
structure( | ||
function(x) { | ||
x | ||
}, | ||
class = c("all_choices", "delayed_choices") | ||
) | ||
} | ||
|
||
#' @export | ||
#' @rdname delayed_choices | ||
first_choice <- function() { | ||
structure( | ||
function(x) { | ||
if (length(x) == 0L) { | ||
x | ||
} else if (is.atomic(x)) { | ||
x[1L] | ||
} else if (inherits(x, "delayed_data")) { | ||
original_fun <- x$subset | ||
added_fun <- function(x) x[1L] | ||
x$subset <- function(data) { | ||
added_fun(original_fun(x)) | ||
x | ||
} | ||
} | ||
}, | ||
class = c("delayed_choices") | ||
) | ||
} | ||
|
||
#' @export | ||
#' @rdname delayed_choices | ||
last_choice <- function() { | ||
structure( | ||
function(x) { | ||
if (length(x) == 0L) { | ||
x | ||
} else if (is.atomic(x)) { | ||
x[length(x)] | ||
} else if (inherits(x, "delayed_data")) { | ||
original_fun <- x$subset | ||
added_fun <- function(x) x[length(x)] | ||
x$subset <- function(data) { | ||
added_fun(original_fun(x)) | ||
x | ||
} | ||
|
||
} | ||
}, | ||
class = c("delayed_choices") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.