3 ms·
I’m confused how this makes the hack around mutate better? In particular the article says that instead of … |> mutate(foo = f(foo)) |> … You can write df
by dan-robertson 3y ago
I’m confused how this makes the hack around mutate better? In particular the article says that instead of
… |> mutate(foo = f(foo)) |> …
You can write
df$foo <|> f
But that seems to not be the case? You need to introduce new names, e.g.
… -> tmp
tmp$foo <|> f
tmp |> …
Which seems worse to me. Maybe I’m missing something.
For comparison, consider jq's |= operator where you might write e.g.
… | (.foo |= f) | …
Which I think composes better with pipelines that do not “mutate” (or rather, make substitutions)
- dash2 3y agoNo, you can indeed write `df$foo <|> f()`.
- dan-robertson 3y agoHow do you use it in the middle of a pipeline like the example with mutate?
- dash2 3y agoThat’s fair. But that’s the way mutate is designed: it uses `foo` as shorthand for `df$foo`. You could do …|> (\(x) x[vars] <|> bar())() But now we are getting into self-parody… as the article says, it’s a shame there’s no nice anonymous function call syntax. Or possibly … |> within(foo <|> bar()) |> …