Skip to content

Commit

Permalink
Use is_top = FALSE as default (#400)
Browse files Browse the repository at this point in the history
This was prompted by a missed case that should have had `is_top = FALSE`
  • Loading branch information
eutwt authored Nov 15, 2022
1 parent 5750999 commit d901487
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions R/tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ globalVariables(dt_funs)

capture_dots <- function(.data, ..., .j = TRUE) {
dots <- enquos(..., .named = .j)
dots <- map(dots, dt_squash, data = .data, j = .j)
dots <- map(dots, dt_squash, data = .data, j = .j, is_top = TRUE)

# Remove names from any list elements
is_list <- map_lgl(dots, is.list)
Expand All @@ -45,7 +45,7 @@ capture_new_vars <- function(.data, ...) {
dots <- as.list(enquos(..., .named = TRUE))
for (i in seq_along(dots)) {
dot <- dots[[i]]
dot <- dt_squash(dot, data = .data)
dot <- dt_squash(dot, data = .data, is_top = TRUE)
if (is.null(dot)) {
dots[i] <- list(NULL)
} else {
Expand All @@ -68,7 +68,7 @@ capture_dot <- function(.data, x, j = TRUE) {
}

# squash quosures
dt_squash <- function(x, env, data, j = TRUE, is_top = TRUE) {
dt_squash <- function(x, env, data, j = TRUE, is_top = FALSE) {
if (is_atomic(x) || is_null(x)) {
x
} else if (is_symbol(x)) {
Expand Down Expand Up @@ -114,13 +114,13 @@ dt_squash <- function(x, env, data, j = TRUE, is_top = TRUE) {
call <- call2("across", x)
dt_squash_across(call, env, data, j, is_top)
} else if (is_call(x)) {
dt_squash_call(x, env, data, j = j, is_top)
dt_squash_call(x, env, data, j = j)
} else {
abort("Invalid input")
}
}

dt_squash_call <- function(x, env, data, j = TRUE, is_top = TRUE) {
dt_squash_call <- function(x, env, data, j = TRUE) {
if (is_mask_pronoun(x)) {
var <- x[[3]]
if (is_call(x, "[[")) {
Expand All @@ -132,7 +132,7 @@ dt_squash_call <- function(x, env, data, j = TRUE, is_top = TRUE) {
sym(paste0("..", var))
}
} else if (is_call(x, c("coalesce", "replace_na"))) {
args <- lapply(x[-1], dt_squash, env, data, j, is_top)
args <- lapply(x[-1], dt_squash, env, data, j)
call2("fcoalesce", !!!args)
} else if (is_call(x, "case_when")) {
# case_when(x ~ y) -> fcase(x, y)
Expand All @@ -144,7 +144,7 @@ dt_squash_call <- function(x, env, data, j = TRUE, is_top = TRUE) {
x[[3]]
)
}))
args <- lapply(args, dt_squash, env = env, data = data, j = j, is_top)
args <- lapply(args, dt_squash, env = env, data = data, j = j)
call2("fcase", !!!args)
} else if (is_call(x, "cur_data")) {
quote(.SD)
Expand All @@ -169,7 +169,7 @@ dt_squash_call <- function(x, env, data, j = TRUE, is_top = TRUE) {
}

x[[1]] <- quote(fifelse)
x[-1] <- lapply(x[-1], dt_squash, env, data, j = j, is_top)
x[-1] <- lapply(x[-1], dt_squash, env, data, j = j)
x
} else if (is_call(x, c("lag", "lead"))) {
if (is_call(x, "lag")) {
Expand Down Expand Up @@ -242,7 +242,7 @@ dt_squash_call <- function(x, env, data, j = TRUE, is_top = TRUE) {
}
call
} else {
x[-1] <- lapply(x[-1], dt_squash, env, data, j = j, is_top = FALSE)
x[-1] <- lapply(x[-1], dt_squash, env, data, j = j)
x
}
}
Expand Down

0 comments on commit d901487

Please sign in to comment.