Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tidyverse/dplyr
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 13, 2017
2 parents 5ac9490 + 7da43c8 commit 4d2b9f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dplyr 0.7.0.9000

* Fix undefined behaviour in `between()`, where `NA_REAL` were assigned instead of `NA_LOGICAL`. (#2855, @zeehio)

# dplyr 0.7.0

## New data, functions, and features
Expand Down
4 changes: 2 additions & 2 deletions src/between.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ LogicalVector between(NumericVector x, double left, double right) {

if (NumericVector::is_na(left) || NumericVector::is_na(right)) {
for (int i = 0; i < n; ++i)
out[i] = NA_REAL;
out[i] = NA_LOGICAL;
return out;
}

for (int i = 0; i < n; ++i) {
if (NumericVector::is_na(x[i])) {
out[i] = NA_REAL;
out[i] = NA_LOGICAL;
} else if ((x[i] >= left) && (x[i] <= right)) {
out[i] = true;
} else {
Expand Down
15 changes: 10 additions & 5 deletions vignettes/programming.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ mutate_y <- function(df) {
}
mutate_y(df1)
# Before dplyr is released, this will give a nice error message
```

If this function is in a package, using `.data` also prevents `R CMD check` from giving a NOTE about undefined global variables (provided that you've also imported `rlang::.data` with `@importFrom rlang .data`).
Expand Down Expand Up @@ -412,25 +411,31 @@ In practice, the formula is the better of the two options because it captures th

```{r}
f <- function(x) {
~ x
quo(x)
}
x1 <- f(10)
x2 <- f(100)
```

It might look like the expressions are the same if you print them out. But look carefully at the environments --- they're different.
It might look like the expressions are the same if you print them out.

```{r}
x1
x2
```

When we evaluate those formulas using `rlang::eval_tidy()`, we see that they yield different values:

But if you inspect the environments using `rlang::get_env()` --- they're different.
```{r, message = FALSE}
library(rlang)
get_env(x1)
get_env(x2)
```

Further, when we evaluate those formulas using `rlang::eval_tidy()`, we see that they yield different values:

```{r}
eval_tidy(x1)
eval_tidy(x2)
```
Expand Down

0 comments on commit 4d2b9f7

Please sign in to comment.