Skip to content

Commit

Permalink
Merge pull request #493 from yjunechoe/tidyselect-coverage
Browse files Browse the repository at this point in the history
A complete tidyselect integration for the `columns` argument in validation functions
  • Loading branch information
rich-iannone committed Oct 28, 2023
2 parents 03917d7 + 3461c33 commit ca26d12
Show file tree
Hide file tree
Showing 40 changed files with 415 additions and 142 deletions.
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

0 comments on commit ca26d12

Please sign in to comment.