tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
957 stars 157 forks source link

Issue with lazy evaluation #195

Closed lionel- closed 4 years ago

lionel- commented 5 years ago
library(magrittr)

gen <- function(x) function() eval(quote(x))

fn <- gen(1)
fn()
#> [1] 1

fn <- 1 %>% gen()
fn()
#> $value
#> function () 
#> eval(quote(x))
#> <bytecode: 0x7fcef8570800>
#> <environment: 0x7fcef89f5520>
#> 
#> $visible
#> [1] TRUE

Fixed if forced:

gen <- function(x) {
  force(x)
  function() eval(quote(x))
}

fn <- 1 %>% gen()
fn()
#> [1] 1
lionel- commented 4 years ago

Fixed by #218