-
Notifications
You must be signed in to change notification settings - Fork 0
Adds interaction variable to picks #11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
48f9d12
Add 0-*.R files from teal.transform redesign_extraction@main branch
m7pr 71aea07
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] f65949d
fix rcmd check
gogonzo 129ef51
move teal.transform to suggests
m7pr e9a1e62
fix: adds js and css that was missing
averissimo 83deac7
feat: moving interaction feature here
averissimo d662d9c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] a8a8854
chore: comment full code of mutate_operators
averissimo eeb1cc8
fix rcmd check and lintrs
gogonzo 33cce3d
hopefully fix cicd
gogonzo c4371f4
fix spelling
gogonzo d10ed88
Update R/0-module_picks.R
averissimo 2b5bb32
[skip style] [skip vbump] Restyle files
github-actions[bot] 6eda79b
feat: convert choices selected to variables
averissimo d81a888
move function
averissimo ddaf2c7
Merge branch 'redesign_extraction@main' into 279-interactive_variables
averissimo 14c9860
Merge branch 'main' into 279-interactive_variables
averissimo 7e6ea35
[skip style] [skip vbump] Restyle files
github-actions[bot] dd9ab9e
Merge remote-tracking branch 'origin/main' into 279-interactive_varia…
averissimo f9bfe44
chore: fix merge issues
averissimo 4a7e0ea
fix: tests and checks
averissimo 0c77a31
feat: only match first operator
averissimo 3b87885
fix: ensure uniqueness of operators
averissimo 7d50773
docs: adds interaction vars
averissimo 09b1327
chore: fix linter
averissimo 60e092d
chore: fix spelling
averissimo d59c76f
fix: operators only work within teal.picks resolver
averissimo 1412882
feat: persist operators when selected is not changed
averissimo 80c5e0c
feat: allow to filter operators
averissimo 7313a0e
feat: support values
averissimo c1dec2c
[skip style] [skip vbump] Restyle files
github-actions[bot] 489b30b
feat: adds warning when using interaction_vars outside picks
averissimo 6392d56
feat: sends error message when trying to filter by more than 1 comple…
averissimo 79620e9
[skip style] [skip vbump] Restyle files
github-actions[bot] ba37037
Merge remote-tracking branch 'origin/main' into 279-interactive_varia…
averissimo 3918083
fix: warning in tests
averissimo 4ba689a
chore: fix linter errors
averissimo 99b1816
Merge remote-tracking branch 'origin/main' into 279-interactive_varia…
averissimo a2e2d3b
fix: module merges without operator when none is selected
averissimo fd39d75
feat: add exports
averissimo 5e392cb
chore: fix linter error
averissimo 8eaa426
fix: better exports
averissimo 1212311
Merge remote-tracking branch 'origin/main' into 279-interactive_varia…
averissimo 10fa142
chore: remove todo
averissimo 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| #' Declare interaction variable pairs for `tidyselect` | ||
| #' | ||
| #' Used inside `tidyselect` expressions to declare a pair of variables that | ||
| #' interact with each other. The pair is recorded in the selection environment | ||
| #' and the positions of both variables within the available variables are | ||
| #' returned. | ||
| #' | ||
| #' @param var1 An unquoted variable name. | ||
| #' @param var2 An unquoted variable name that interacts with `var1`. | ||
| #' @param vars Character vector of available variable names, retrieved | ||
| #' automatically via [tidyselect::peek_vars()]. | ||
| #' | ||
| #' @return An integer vector of length 2 giving the positions of `var1` and | ||
| #' `var2` in `vars`, or `NA` where a variable is not found. | ||
| #' | ||
| #' @export | ||
| interaction_vars <- function(var1, var2, vars = tidyselect::peek_vars(fn = "interaction_vars")) { | ||
| new_var <- c(as.character(substitute(var1)), as.character(substitute(var2))) | ||
| result <- match(new_var, vars) | ||
| if (isTRUE(select_env$active)) { # Only set operators under `teal.picks` evaluation context | ||
| new_operator <- structure( | ||
| new_var, | ||
| class = c("interaction", "operator"), | ||
| var_name = sprintf("%s:%s", new_var[[1]], new_var[[2]]) | ||
| ) | ||
| select_env$operators <- select_env$operators %||% list() | ||
| select_env$operators[[length(select_env$operators) + 1]] <- new_operator | ||
| } else { | ||
| warning( | ||
| "interaction_vars() should only be used within a tidyselect context in teal.picks.", | ||
| " The interaction will not be recorded, and the variables will be treated as independent.", | ||
| call. = FALSE | ||
| ) | ||
| } | ||
| result | ||
| } | ||
|
|
||
| .operator_mutate <- function(x, new_choice, data) { | ||
| UseMethod(".operator_mutate") | ||
| } | ||
|
|
||
| #' @method .operator_mutate interaction | ||
| #' @keywords internal | ||
| .operator_mutate.interaction <- function(x, new_choice, data) { | ||
| checkmate::assert_character(x, len = 2) | ||
| checkmate::assert_string(new_choice) | ||
| checkmate::assert_data_frame(data) | ||
| dplyr::mutate( | ||
| data, | ||
| !!new_choice := rlang::eval_bare(.operator_mutate_args(x)) | ||
| ) | ||
| } | ||
|
|
||
| #' @method call_condition_operators interaction | ||
| #' @keywords internal | ||
| call_condition_operators.interaction <- function(x, choices) { | ||
| checkmate::assert_character(x, len = 2) | ||
| checkmate::assert_character(choices) | ||
| as.call( | ||
| list( | ||
| quote(`%in%`), | ||
| as.call( | ||
| list(quote(paste), as.name(x[1]), as.name(x[2]), sep = ":") | ||
| ), | ||
| unname(choices) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| call_condition_operators <- function(x, choices) { | ||
| UseMethod("call_condition_operators") | ||
| } | ||
|
|
||
| .operator_mutate_args <- function(x) { | ||
| UseMethod(".operator_mutate_args") | ||
| } | ||
|
|
||
| #' @method .operator_mutate interaction | ||
| #' @keywords internal | ||
| .operator_mutate_args.interaction <- function(x) { | ||
| checkmate::assert_character(x, len = 2) | ||
| as.call(c(list(quote(paste)), lapply(x, as.name), list(sep = ":"))) | ||
| } | ||
|
|
||
|
|
||
| # Environment to store interaction variable pairs during `tidyselect` evaluation | ||
| # This is used to communicate between the `interaction_vars()` function and the resolver that | ||
| # processes the picks with variables that interact. | ||
| # The resolver will look for this information in the environment to know which variables are | ||
| # meant to interact and need to be combined in the data. | ||
| select_env <- new.env(parent = emptyenv()) | ||
|
|
||
| .is_operator_selected <- function(operators, x) { | ||
| if (length(operators) == 0L || length(x) == 0L) { | ||
| return(FALSE) | ||
| } | ||
| any(vapply(operators, attr, "var_name", FUN.VALUE = character(1L), USE.NAMES = FALSE) %in% x) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| #' @import shiny | ||
| #' @importFrom rlang := | ||
| NULL |
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Uh oh!
There was an error while loading. Please reload this page.