You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and got thinking it would be really nice to just be able to write it as
map(f(...,x,...))
where the fact that I used x in f(x) implies that f(x) is to be applied element wise to x.
In essence, I was imagining a more implicit function, call it zip, in keeping with standard functional naming, that would automatically vectorize the passed expression. That is, it would take all the free variables in the expression passed to it, look them up in it's environment, expand them all to equal length vectors, and map across them all.
In terms of the wider tidyverse, you could replace this sort how-many-times-do-I-have-to-type-xyz code
data |> mutate(r = pmap_vec(list(x,y,z), \(x,y,z) f(...,x,y,z,...)))
or this less verbose but more sinfully-stateful code
data |> rowwise() |> mutate(r = f(...,x,y,z,...)) |> ungroup()
with just
data |> mutate(r = zip(f(..,x,y,z,...)))
Hopefully that makes sense. Have no idea if this is even practical, but figured I would suggest it. Maybe it it would make sense for the mutate.by option to also accept 'row' too to avoid stateful grouping/ungrouping.
Feel free to just close this if you want.
The text was updated successfully, but these errors were encountered:
I think this is a cool idea, but it just feels a bit too magical for purrr, which has generally been moving away from "magic" and towards explicitness.
Was writing this sort of code
and got thinking it would be really nice to just be able to write it as
where the fact that I used
x
inf(x)
implies thatf(x)
is to be applied element wise tox
.In essence, I was imagining a more implicit function, call it
zip
, in keeping with standard functional naming, that would automatically vectorize the passed expression. That is, it would take all the free variables in the expression passed to it, look them up in it's environment, expand them all to equal length vectors, and map across them all.In terms of the wider tidyverse, you could replace this sort how-many-times-do-I-have-to-type-xyz code
or this less verbose but more sinfully-stateful code
with just
Hopefully that makes sense. Have no idea if this is even practical, but figured I would suggest it. Maybe it it would make sense for the
mutate
.by
option to also accept'row'
too to avoid stateful grouping/ungrouping.Feel free to just close this if you want.
The text was updated successfully, but these errors were encountered: