rlang icon indicating copy to clipboard operation
rlang copied to clipboard

Should `inject()` strip srcrefs?

Open hadley opened this issue 8 months ago • 0 comments

To avoid this problem:

library(rlang)
power1 <- function(exp) {
  inject(function(x) x ^ !!exp)
}
funs <- lapply(1:2, power1)
funs
#> [[1]]
#> function(x) x ^ !!exp
#> <environment: 0x107033e08>
#> 
#> [[2]]
#> function(x) x ^ !!exp
#> <environment: 0x107032ba8>

lapply(funs, \(f) structure(f, srcref= NULL))
#> [[1]]
#> function (x) 
#> x^1L
#> <environment: 0x107033e08>
#> 
#> [[2]]
#> function (x) 
#> x^2L
#> <environment: 0x107032ba8>

Created on 2023-11-02 with reprex v2.0.2

hadley avatar Nov 02 '23 19:11 hadley