r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
282 stars 65 forks source link

Map functions with vctrs semantics #1941

Closed tzakharko closed 3 weeks ago

tzakharko commented 3 weeks ago

It appreas that the ecosystem is still lacking a map primitive with vctrs-compatible semantics. I recall there was an effort to implement mapping as part of vctrs (e.g. #1227), which was abandoned in favour of map_vec() in purrr. However, purrr does not offer vctrs-compatible semantics, in particular it has inconsistent treatment of data frames (see for example https://github.com/tidyverse/purrr/issues/838).

I believe that the vctrs approach to treating tables as row-iterable vectors is very powerful and allows the intuitive composition of complex data. This semantics also powers many advanced features within dplyr. Are there plans to bring this to list iteration?

DavisVaughan commented 3 weeks ago

treating tables as row-iterable vectors

slider::slide() does exactly that and is likely as close as we will get https://slider.r-lib.org/articles/rowwise.html

It uses vctrs iteration under the hood and is mostly implemented in C to make it as fast as possible, but it still does have to callback to R to call the .f function on every row

tzakharko commented 3 weeks ago

Thanks, @DavisVaughan! I was not aware that slider is positioned as a general solution to this problem (my hope that there were plans for this in vctrs or purrr). I suppose that's another package to add to the dependency list :)

DavisVaughan commented 3 weeks ago

slider is well maintained and as lightweight dependency wise as purrr, so it should work pretty well for your use cases, I think!