tidyverse / magrittr

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

Do not create a functional sequence when there is variable `.` #188

Closed yutannihilation closed 5 years ago

yutannihilation commented 5 years ago

c.f. https://twitter.com/yutannihilat_en/status/1075758245048836096

If there is actually a variable . in the caller's environment, the user probably indends to evaluate it, not to create a functional sequence.

library(magrittr)

purrr::map(1:3, ~ . %>% sqrt)
#> [[1]]
#> Functional sequence with the following components:
#> 
#>  1. sqrt(.)
#> 
#> Use 'functions' to extract the individual functions. 
#> 
#> [[2]]
#> Functional sequence with the following components:
#> 
#>  1. sqrt(.)
#> 
#> Use 'functions' to extract the individual functions. 
#> 
#> [[3]]
#> Functional sequence with the following components:
#> 
#>  1. sqrt(.)
#> 
#> Use 'functions' to extract the individual functions.

Created on 2018-12-21 by the reprex package (v0.2.1)

hadley commented 5 years ago

I think this makes would make magrittr more surprising.