-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Pipes are great, but if they are used outside dplyr where the syntax is optimized, e.g. for manipulating elements of a list of rows of data.frame code quickly gets more complex (and less readable) than it should be. The names are in my opinion self-explanatory enough that someone who does not know them could still understand what is happening, maybe more easily than the alternative that only uses standard R.
This is a proposal for introducing 3 new pipe operators to address this.
Element-wise pipes (could e.g. also replace df/add_name_col to reduce complexity):
# this is too verbose for what it does - and sapply's defaults are stupid
list_obj %>%
sapply(function(x) myfun(x, some_arg=3), simplify=FALSE, USE.NAMES=TRUE)
# or: sapply(myfun, some_arg=3, simplify=FALSE, USE.NAMES=TRUE)
list_obj %elm>%
myfun(some_arg=3)Row- and column-wise call pipes: Use each row (or column) of a data.frame/matrix as arguments to call an arbitrary function with. This could support #63 (and at the same time make code that is based on it easier to debug):
# not sure if this even works with named arguments
mat_obj %>%
apply(1, function(..., additional_arg=5) do.call(myfun, c(list(...),
list(additional_arg=additional_arg))))
mat_obj %row>% # or %col>%
myfun(additional_arg=5)