Skip to content

Commit

Permalink
Detect data pronouns subsetted with [[
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed May 4, 2017
1 parent 415ff38 commit 055fb8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions R/utils-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ expr_substitute <- function(expr, old, new) {
expr
}

is_pronoun <- function(expr) {
is_lang(expr, quote(`$`)) && identical(node_cadr(expr), quote(.data))
sym_dollar <- quote(`$`)
sym_brackets2 <- quote(`[[`)
is_data_pronoun <- function(expr) {
is_lang(expr, list(sym_dollar, sym_brackets2)) &&
identical(node_cadr(expr), quote(.data))
}
tidy_text <- function(quo, width = 60L) {
expr <- f_rhs(quo)
if (is_pronoun(expr)) {
if (is_data_pronoun(expr)) {
as_string(node_cadr(node_cdr(expr)))
} else {
quo_text(quo, width = width)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,6 @@ test_that("rowwise fails gracefully on raw columns (#1803)", {
})

test_that("group_by() names pronouns correctly (#2686)", {
gdf <- group_by(tibble(x = 1), .data$x)
expect_named(gdf, "x")
expect_named(group_by(tibble(x = 1), .data$x), "x")
expect_named(group_by(tibble(x = 1), .data[["x"]]), "x")
})
4 changes: 2 additions & 2 deletions tests/testthat/test-mutate.r
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ test_that("ntile falls back to R (#1750)", {
})

test_that("mutate() names pronouns correctly (#2686)", {
df <- mutate(tibble(x = 1), .data$x)
expect_named(df, "x")
expect_named(mutate(tibble(x = 1), .data$x), "x")
expect_named(mutate(tibble(x = 1), .data[["x"]]), "x")
})


Expand Down

0 comments on commit 055fb8b

Please sign in to comment.