Skip to content

Commit

Permalink
hybrid evaluator did not use correct environment. closes #403
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Apr 24, 2014
1 parent 26a7fab commit 89fa6f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -141,6 +141,8 @@ dplyr 0.2 adds three new verbs:

* `group_by` only creates one group for NA (#401).

* Hybrid evaluator did not evaluate expression in correct environment (#403).

# dplyr 0.1.3

## Bug fixes
Expand Down
1 change: 1 addition & 0 deletions inst/include/dplyr/Result/CallProxy.h
Expand Up @@ -37,6 +37,7 @@ namespace dplyr {
for( int i=0; i<n; i++){
proxies[i].set( subsets[proxies[i].symbol] ) ;
}

Shield<SEXP> res( call.eval(env) ) ;
return res ;
} else if( TYPEOF(call) == SYMSXP) {
Expand Down
2 changes: 1 addition & 1 deletion inst/include/dplyr/Result/GroupedHybridCall.h
Expand Up @@ -15,7 +15,7 @@ namespace dplyr {
SEXP eval(){
if( TYPEOF(call) == LANGSXP ){
substitute(call) ;
return Rf_eval( call, R_GlobalEnv ) ;
return Rf_eval( call, env ) ;
} else if(TYPEOF(call) == SYMSXP) {
if(subsets.count(call)){
return subsets.get(call, indices) ;
Expand Down
2 changes: 1 addition & 1 deletion inst/include/dplyr/Result/HybridCall.h
Expand Up @@ -14,7 +14,7 @@ namespace dplyr {
SEXP eval(){
if( TYPEOF(call) == LANGSXP ){
substitute(call) ;
return Rf_eval( call, R_GlobalEnv ) ;
return Rf_eval( call, env ) ;
} else if(TYPEOF(call) == SYMSXP) {
if(subsets.count(call)){
return subsets.get_variable(call) ;
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-mutate.r
Expand Up @@ -201,3 +201,12 @@ test_that("mutate errors when results are not compatible accross groups (#299)",
test_that("assignments are forbidden (#315)", {
expect_error(mutate(mtcars, cyl2 = { x <- cyl^2; -x } ))
})

test_that("hybrid evaluator uses correct environment (#403)", {
func1 <- function() {
func2 <- function(x) floor(x)
mutate(mtcars, xx = func2(mpg / sum(mpg)))
}
res <- func1()
expect_equal(res$xx, rep(0,nrow(res)) )
})

0 comments on commit 89fa6f9

Please sign in to comment.