[R] nth kludge

@vi@e@gross m@iii@g oii gm@ii@com @vi@e@gross m@iii@g oii gm@ii@com
Wed Mar 8 21:23:53 CET 2023

I see many are not thrilled with the concise but unintuitive way it is
suggested you use with the new R pipe function. 
I am wondering if any has created one of a family of functions that might be
more intuitive if less general.
Some existing pipes simply allowed you to specify where in an argument list
to put the results from the earlier pipeline as in:
. %>% func(first, . , last)
In the above common case, it substituted into the second position.
What would perhaps be a useful variant is a function that does not evaluate
it's arguments and expects a first argument passed from the pipe and a
second argument that is a number like 2 or 3 and  a third  argument that is
the (name of) a function and remaining arguments.
The above might look like:
. %>% the_nth(2, func, first , last)
The above asks to take the new implicitly passed first argument which I will
illustrate with a real argument as it would also work without a pipeline:
the_nth(piped, 2, func, first, last)
So it would make a list out of the remaining arguments that looks like
list(first, last) and interpolate piped at position 2 to make list(first,
piped, last) and then use something like do.call()
do.call(func, list(first, piped, last))
I am not sure if this is much more readable, but seems like a
straightforward function to write, and perhaps a decent version could make
it into the standard library some year that is general and more useful than
the darn anonymous lambda notation.

	[[alternative HTML version deleted]]

More information about the R-help mailing list