tidyverse / magrittr

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

Missing/empty name throws error #214

Closed burchill closed 4 years ago

burchill commented 4 years ago

This may be an edge case not worth worrying about, but an empty name seems to mess up the pipes.

library(magrittr)
# Make an empty name
x <- substitute()
# Works fine
identity(x) 
# Error in identity(.) : argument "_lhs" is missing, with no default
x %>% identity() 

I don't really see this being a big issue, but I ended up stumbling upon it, so who knows.

lionel- commented 4 years ago

I guess you've rearranged the reprex before posting? I see:

x <- substitute()

identity(x)
#> Error in identity(x) : argument "x" is missing, with no default

That's because a symbol that evaluates to the missing argument causes the error. What works is a call that returns the missing argument:

identity(substitute())
#>

Unfortunately it would be too much trouble to fix this corner case in magrittr, we would have to hide the evaluation behind an extra call. This would affect backtraces for example.