Currying functions in R

女生的网名这么多〃 提交于 2019-12-03 16:19:15

问题


Is it possible to use currying in R?

One possibility is to have special paste functions (it can be considered as a follow up to here), e.g. (in incorrect code):

'%+%' <- (sep)function(x,y) paste(x,y,sep=sep)
"a"%+%("")"b"%+%("_")"c" #gives "ab_c"

What would be a possible implementation in R?

PS: The paste is just an example, I am curious about the possibilities of R...


回答1:


It is possible to curry in R, and there is a definition in the ROxygen package. See the discussion here




回答2:


The standard place for functional programming in R is now the functional library, this library substitutes the ROxigen library that is discussed here :

library(functional)
newfunc <- Curry(oldfunc,x=5)


来源:https://stackoverflow.com/questions/5354364/currying-functions-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!