Skip to content

Commit

Permalink
use rlang::env_unbind()
Browse files Browse the repository at this point in the history
and adapt snapshots to dev rlang
  • Loading branch information
romainfrancois committed Jun 30, 2021
1 parent 3660cba commit 0aaf65e
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 36 deletions.
4 changes: 3 additions & 1 deletion R/arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ arrange_rows <- function(.data, dots) {

if (inherits(cnd, "dplyr:::mutate_error")) {
# reverse the name mangling
bullets <- gsub("^^--arrange_quosure_", "..", cnd$bullets, fixed = TRUE)
bullets <- cnd$bullets
names(bullets)[1] <- "x"
bullets <- gsub("^^--arrange_quosure_", "..", bullets, fixed = TRUE)
} else {
bullets <- c(x = conditionMessage(cnd))
}
Expand Down
20 changes: 2 additions & 18 deletions src/mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ SEXP dplyr_mask_add(SEXP env_private, SEXP s_name, SEXP chunks) {
return R_NilValue;
}

// no C-api for rm() so callback to R :shrug:
SEXP get_rm_call() {
SEXP rm_call = PROTECT(Rf_lang3(dplyr::symbols::rm, R_NilValue, R_NilValue));
SET_TAG(CDDR(rm_call), dplyr::symbols::envir);
R_PreserveObject(rm_call);
UNPROTECT(1);
return rm_call;
}

void rm(SEXP name, SEXP env) {
static SEXP rm_call = get_rm_call();
SETCADR(rm_call, name);
SETCADDR(rm_call, env);
Rf_eval(rm_call, R_BaseEnv);
}

SEXP dplyr_mask_remove(SEXP env_private, SEXP s_name) {
SEXP name = STRING_ELT(s_name, 0);

Expand All @@ -102,10 +86,10 @@ SEXP dplyr_mask_remove(SEXP env_private, SEXP s_name) {

SEXP chops = PROTECT(Rf_findVarInFrame(env_private, dplyr::symbols::chops));
SEXP sym_name = PROTECT(rlang::str_as_symbol(name));
rm(sym_name, chops);
rlang::env_unbind(chops, sym_name);

SEXP mask = PROTECT(Rf_findVarInFrame(env_private, dplyr::symbols::mask));
rm(sym_name, ENCLOS(mask));
rlang::env_unbind(ENCLOS(mask), sym_name);

UNPROTECT(4);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/across.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# if_any() and if_all() aborts when predicate mistakingly used in .cols= (#5732)

Code
(expect_error(filter(df, if_any(~.x > 5))))
(expect_error(filter(df, if_any(~ .x > 5))))
Output
<error/dplyr_error>
Problem with `filter()` input `..1`.
Expand All @@ -35,7 +35,7 @@
i The first argument `.cols` selects a set of columns.
i The second argument `.fns` operates on each selected columns.
Code
(expect_error(filter(df, if_all(~.x > 5))))
(expect_error(filter(df, if_all(~ .x > 5))))
Output
<error/dplyr_error>
Problem with `filter()` input `..1`.
Expand All @@ -45,7 +45,7 @@
i The first argument `.cols` selects a set of columns.
i The second argument `.fns` operates on each selected columns.
Code
(expect_error(filter(df, !if_any(~.x > 5))))
(expect_error(filter(df, !if_any(~ .x > 5))))
Output
<error/dplyr_error>
Problem with `filter()` input `..1`.
Expand All @@ -55,7 +55,7 @@
i The first argument `.cols` selects a set of columns.
i The second argument `.fns` operates on each selected columns.
Code
(expect_error(filter(df, !if_all(~.x > 5))))
(expect_error(filter(df, !if_all(~ .x > 5))))
Output
<error/dplyr_error>
Problem with `filter()` input `..1`.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/arrange.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
tibble(x = 1) %>% arrange(y)
Error <dplyr_error>
arrange() failed at implicit mutate() step.
* Problem with `mutate()` column `..1`.
x Problem with `mutate()` column `..1`.
i `..1 = y`.
x object 'y' not found

Expand All @@ -22,7 +22,7 @@
tibble(x = 1) %>% arrange(rep(x, 2))
Error <dplyr_error>
arrange() failed at implicit mutate() step.
* Problem with `mutate()` column `..1`.
x Problem with `mutate()` column `..1`.
i `..1 = rep(x, 2)`.
i `..1` must be size 1, not 2.

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/colwise-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
---

Code
filter_all(mtcars, list(~. > 0))
filter_all(mtcars, list(~ . > 0))
Error <rlang_error>
`.vars_predicate` must be a function or a call to `all_vars()` or `any_vars()`, not a list.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/deprec-funs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
---

Code
funs(~mp[.])
funs(~ mp[.])
Error <rlang_error>
`~mp[.]` must be a function name (quoted or unquoted) or an unquoted call, not `~`.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
---

Code
data.frame(x = 1, y = 1) %>% filter(across(everything(), ~.x > 0))
data.frame(x = 1, y = 1) %>% filter(across(everything(), ~ .x > 0))
Output
x y
1 1 1
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/_snaps/group-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
df %>% ungroup(x)
Error <rlib_error_dots_nonempty>
`...` is not empty.
We detected these problematic arguments:
i These dots only exist to allow future extensions and should be empty.
x We detected these problematic arguments:
* `..1`
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
i Did you misspecify an argument?

---

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/group_map.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# group_map() give meaningful errors

Code
mtcars %>% group_by(cyl) %>% group_modify(~data.frame(cyl = 19))
mtcars %>% group_by(cyl) %>% group_modify(~ data.frame(cyl = 19))
Error <rlang_error>
The returned data frame cannot contain the original grouping variables: cyl.

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-colwise-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ test_that("colwise filter support .data$. in the quosure versions", {

test_that("colwise filter() give meaningful errors", {
expect_snapshot(error = TRUE, filter_if(mtcars, is_character, all_vars(. > 0)))
expect_snapshot(error = TRUE, filter_all(mtcars, list(~. > 0)))
expect_snapshot(error = TRUE, filter_all(mtcars, list(~ . > 0)))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-deprec-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ test_that("funs() give meaningful error messages", {
withr::local_options(lifecycle_verbosity = "quiet")

expect_snapshot(error = TRUE, funs(function(si) { mp[si] }))
expect_snapshot(error = TRUE, funs(~mp[.]))
expect_snapshot(error = TRUE, funs(~ mp[.]))
})

0 comments on commit 0aaf65e

Please sign in to comment.