Skip to content
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

A complete tidyselect integration for the columns argument in validation functions #493

Merged
merged 42 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b09ded9
streamlining internal tidyselect first draft
yjunechoe Oct 17, 2023
5cedd20
[temp] make error msg regex test generally for column-related error
yjunechoe Oct 17, 2023
2d939aa
keep original deparse handling of vars
yjunechoe Oct 17, 2023
3f7cce4
be intentional about passing character vector of columns
yjunechoe Oct 17, 2023
1f04ebc
remove expr constraint to bring the environment along for ordinary ev…
yjunechoe Oct 17, 2023
85217be
work with vars() as expr not quosure since we don't care about the env
yjunechoe Oct 17, 2023
9fcbaed
don't use all_of() for ordinarily evaluated column argument
yjunechoe Oct 17, 2023
e72e49b
more explicit code for resolving tbl
yjunechoe Oct 17, 2023
ac65f40
exception for when tbl is empty like in specially()
yjunechoe Oct 17, 2023
d386432
use tidyselect in rows_distinct
yjunechoe Oct 17, 2023
1382a08
tidyselect tests first draft
yjunechoe Oct 17, 2023
099ba5f
namespace tidyselect fns in test
yjunechoe Oct 17, 2023
7e55558
revert all_of for create_validation_step, which uses ordinary evaluation
yjunechoe Oct 17, 2023
14f9878
use all_of
yjunechoe Oct 17, 2023
4cc1c84
implement behavior of NULL with everything()
yjunechoe Oct 17, 2023
91d3102
relax regexp for column not found error
yjunechoe Oct 17, 2023
d7c1eff
tests expect column info from row_distinct() validation step
yjunechoe Oct 17, 2023
7b3ee39
add test for tidyselect where support
yjunechoe Oct 17, 2023
9bc5524
clean up resolve_columns
yjunechoe Oct 17, 2023
982d4c5
use quo_is_null
yjunechoe Oct 17, 2023
719cf6f
use quo_is_call
yjunechoe Oct 17, 2023
5bbe101
simplify defaulting to everything() when column is NULL for rows_dist…
yjunechoe Oct 18, 2023
646ec8e
[chore] probe_columns helpers marked for always receiving chr input
yjunechoe Oct 19, 2023
1978e8d
[chore] some more all_of coverage
yjunechoe Oct 19, 2023
65ae1ad
linter
yjunechoe Oct 19, 2023
a50643d
tidyselect errors only in non-validation-building contexts
yjunechoe Oct 19, 2023
35ae592
missing columns for selection marked as NA
yjunechoe Oct 19, 2023
dddfd1e
Resolve to NA for when NULL passed to columns argument
yjunechoe Oct 19, 2023
af394ab
force tbl/agent in resolve_columns to avoid interrupt promise warnings
yjunechoe Oct 20, 2023
7111ed2
tests for tidyselect column selection error behaviors
yjunechoe Oct 20, 2023
726aed6
test status in validation set directly
yjunechoe Oct 20, 2023
7e492bd
[chore] replace .env$ with all_of()
yjunechoe Oct 20, 2023
bbacbc7
tidyselect columns in rows_complete
yjunechoe Oct 21, 2023
56fb16f
test 0-column selection behavior for rows_* validation functions
yjunechoe Oct 21, 2023
4f07e53
add june as aut
yjunechoe Oct 21, 2023
0585392
use all_of
yjunechoe Oct 22, 2023
f07e396
clean up tidyselect test file
yjunechoe Oct 22, 2023
7b8c66c
tests expect column info from row_complete() validation step
yjunechoe Oct 22, 2023
2255b41
tidyselect for col_exists(); resolves #433
yjunechoe Oct 23, 2023
be5725e
test tidyselect for col_exists()
yjunechoe Oct 23, 2023
8ec5486
more tests for vars() backwards compatibility
yjunechoe Oct 23, 2023
3461c33
col_exists() only fails and never errors for missing column selection
yjunechoe Oct 23, 2023
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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Authors@R: c(
person("Richard", "Iannone", , "rich@posit.co", c("aut", "cre"),
comment = c(ORCID = "0000-0003-3925-190X")),
person("Mauricio", "Vargas", , "mavargas11@uc.cl", c("aut"),
comment = c(ORCID = "0000-0003-1017-7574"))
comment = c(ORCID = "0000-0003-1017-7574")),
person("June", "Choe", , "jchoe001@gmail.com", c("aut"),
comment = c(ORCID = "0000-0002-0701-921X"))
)
License: MIT + file LICENSE
URL: https://rstudio.github.io/pointblank/, https://github.com/rstudio/pointblank
Expand Down
23 changes: 12 additions & 11 deletions R/col_exists.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,25 @@ col_exists <- function(
rlang::as_label(rlang::quo(!!enquo(columns))) %>%
gsub("^\"|\"$", "", .)

# Normalize the `columns` expression
if (inherits(columns, "quosures")) {

columns <-
vapply(
columns,
FUN.VALUE = character(1),
USE.NAMES = FALSE,
FUN = function(x) as.character(rlang::get_expr(x))
)
# Capture the `columns` expression
columns <- rlang::enquo(columns)
if (rlang::quo_is_null(columns)) {
columns <- rlang::quo(tidyselect::everything())
}

# Resolve the columns based on the expression
## Only for `col_exists()`: error gracefully if column not found
columns <- tryCatch(
expr = resolve_columns(x = x, var_expr = columns, preconditions = NULL),
error = function(cnd) cnd$i %||% NA_character_
)

if (is_a_table_object(x)) {

secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_exists(
columns = columns,
columns = tidyselect::all_of(columns),
actions = prime_actions(actions),
label = label,
brief = brief,
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_character.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ col_is_character <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_character(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ col_is_date <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_date(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ col_is_factor <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_factor(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_integer.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ col_is_integer <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_integer(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_logical.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ col_is_logical <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_logical(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ col_is_numeric <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_numeric(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_is_posix.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ col_is_posix <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_is_posix(
columns = columns,
columns = tidyselect::all_of(columns),
label = label,
brief = brief,
actions = prime_actions(actions),
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_between.R
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ col_vals_between <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_between(
columns = columns,
columns = tidyselect::all_of(columns),
left = left,
right = right,
inclusive = inclusive,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_decreasing.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ col_vals_decreasing <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_decreasing(
columns = columns,
columns = tidyselect::all_of(columns),
allow_stationary = allow_stationary,
increasing_tol = increasing_tol,
na_pass = na_pass,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ col_vals_equal <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_equal(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_gt.R
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ col_vals_gt <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_gt(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_gte.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ col_vals_gte <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_gte(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_in_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ col_vals_in_set <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_in_set(
columns = columns,
columns = tidyselect::all_of(columns),
set = set,
preconditions = preconditions,
segments = segments,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_increasing.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ col_vals_increasing <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_increasing(
columns = columns,
columns = tidyselect::all_of(columns),
allow_stationary = allow_stationary,
decreasing_tol = decreasing_tol,
na_pass = na_pass,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_lt.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ col_vals_lt <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_lt(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_lte.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ col_vals_lte <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_lte(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_make_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ col_vals_make_set <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_make_set(
columns = columns,
columns = tidyselect::all_of(columns),
set = set,
preconditions = preconditions,
segments = segments,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_make_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ col_vals_make_subset <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_make_subset(
columns = columns,
columns = tidyselect::all_of(columns),
set = set,
preconditions = preconditions,
segments = segments,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_not_between.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ col_vals_not_between <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_not_between(
columns = columns,
columns = tidyselect::all_of(columns),
left = left,
right = right,
inclusive = inclusive,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_not_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ col_vals_not_equal <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_not_equal(
columns = columns,
columns = tidyselect::all_of(columns),
value = value,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_not_in_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ col_vals_not_in_set <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_not_in_set(
columns = columns,
columns = tidyselect::all_of(columns),
set = set,
preconditions = preconditions,
segments = segments,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_not_null.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ col_vals_not_null <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_not_null(
columns = columns,
columns = tidyselect::all_of(columns),
preconditions = preconditions,
segments = segments,
label = label,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_null.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ col_vals_null <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_null(
columns = columns,
columns = tidyselect::all_of(columns),
preconditions = preconditions,
segments = segments,
label = label,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_regex.R
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ col_vals_regex <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_regex(
columns = columns,
columns = tidyselect::all_of(columns),
regex = regex,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
2 changes: 1 addition & 1 deletion R/col_vals_within_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ col_vals_within_spec <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
col_vals_within_spec(
columns = columns,
columns = tidyselect::all_of(columns),
spec = spec,
na_pass = na_pass,
preconditions = preconditions,
Expand Down
21 changes: 6 additions & 15 deletions R/rows_complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,13 @@ rows_complete <- function(

# Capture the `columns` expression
columns <- rlang::enquo(columns)

if (uses_tidyselect(expr_text = columns_expr)) {

# Resolve the columns based on the expression
columns <- resolve_columns(x = x, var_expr = columns, preconditions = NULL)

} else {

# Resolve the columns based on the expression
if (!is.null(rlang::eval_tidy(columns)) && !is.null(columns)) {
columns <- resolve_columns(x = x, var_expr = columns, preconditions)
} else {
columns <- NULL
}
if (rlang::quo_is_null(columns)) {
columns <- rlang::quo(tidyselect::everything())
}

# Resolve the columns based on the expression
columns <- resolve_columns(x = x, var_expr = columns, preconditions = NULL)

# Resolve segments into list
segments_list <-
resolve_segments(
Expand All @@ -307,7 +298,7 @@ rows_complete <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
rows_complete(
columns = columns,
columns = tidyselect::all_of(columns),
preconditions = preconditions,
segments = segments,
label = label,
Expand Down
21 changes: 6 additions & 15 deletions R/rows_distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,13 @@ rows_distinct <- function(

# Capture the `columns` expression
columns <- rlang::enquo(columns)

if (uses_tidyselect(expr_text = columns_expr)) {

# Resolve the columns based on the expression
columns <- resolve_columns(x = x, var_expr = columns, preconditions = NULL)

} else {

# Resolve the columns based on the expression
if (!is.null(rlang::eval_tidy(columns)) && !is.null(columns)) {
columns <- resolve_columns(x = x, var_expr = columns, preconditions)
} else {
columns <- NULL
}
if (rlang::quo_is_null(columns)) {
columns <- rlang::quo(tidyselect::everything())
}

# Resolve the columns based on the expression
columns <- resolve_columns(x = x, var_expr = columns, preconditions = NULL)

# Resolve segments into list
segments_list <-
resolve_segments(
Expand All @@ -308,7 +299,7 @@ rows_distinct <- function(
secret_agent <-
create_agent(x, label = "::QUIET::") %>%
rows_distinct(
columns = columns,
columns = tidyselect::all_of(columns),
preconditions = preconditions,
segments = segments,
label = label,
Expand Down
Loading
Loading