Created attachment 1639 [details]
TakeWhile patch against trunk r66309
R's functional programming facilities are great. This patch adds a TakeWhile function, modelled after Haskell's takeWhile and python's itertools.takewhile, useful in situations where you want the largest prefix of a list or vector satisfying a predicate. There are probably other useful candidates for adding (e.g. DropWhile) but this seems like a good start.
Patch attached. Includes documentation and regression tests.
This bug list is for bugs/changes to base R. Send suggestions for contributed packages to the package maintainer. Since funprog is not a CRAN package, I don't know who that is, but the DESCRIPTION file should tell you.
Whoops, misunderstood that. Someone who is familiar with funprog.R should take a look.
Created attachment 1640 [details]
TakeWhile patch against trunk r66311 with additional right = TRUE support
Thanks for the response, and sorry for confusing you!
A colleague (Paul Fink) suggested to support right = TRUE as well. Attached is a more extensive patch implementing this as well, including further regression tests and documentation as usual.
(I guess it could make sense to put this function - and possibly others - into a separate package on CRAN, however it seems that R encourages a functional programming style, hence at least in my subjective view it makes more sense to have it right in base. As far as it may serve as a guidance, note that both Python and Haskell have it in their standard library.)