Skip to content

Commit

Permalink
Merge pull request #531 from yjunechoe/tbl_val_comparison-column-symbol
Browse files Browse the repository at this point in the history
Ensure column string is symbol before constructing expression for `col_vals_*()` functions
  • Loading branch information
rich-iannone authored Mar 16, 2024
2 parents ade8a31 + 4aeb80b commit 1cf7733
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions R/interrogate.R
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,6 @@ interrogate_comparison <- function(
# Normalize a column in `vars()` to a `name` object
if (inherits(value, "list")) {
value <- value[1][[1]] %>% rlang::get_expr()
} else {
if (is.character(value)) {
value <- paste0("'", value, "'")
}
}

# Obtain the target column as a label
Expand Down Expand Up @@ -1132,20 +1128,20 @@ tbl_val_comparison <- function(
)

# Construct a string-based expression for the validation
expression <- paste(column, operator, value)
expression <- call(operator, as.symbol(column), value)

if (is_tbl_mssql(table)) {

table %>%
dplyr::mutate(pb_is_good_ = dplyr::case_when(
!!rlang::parse_expr(expression) ~ 1,
!!expression ~ 1,
TRUE ~ 0
))

} else {

table %>%
dplyr::mutate(pb_is_good_ = !!rlang::parse_expr(expression)) %>%
dplyr::mutate(pb_is_good_ = !!expression) %>%
dplyr::mutate(pb_is_good_ = dplyr::case_when(
is.na(pb_is_good_) ~ na_pass,
TRUE ~ pb_is_good_
Expand Down

0 comments on commit 1cf7733

Please sign in to comment.