R - Converting a Function to String -
i working on function behave similar reduce
pass in function , dispatch on arguments. here simple example demonstrate working on.
fun <- function(f){ switch(f, `+` = "addition", stop("undefined") ) } fun(`+`)
now won't work stands because switch
requires character
or numeric
expr
. don't know how convert function f
passed fun
string
.
one approach capture input , deparse call.
fun <- function(f){ switch(deparse(substitute(f)), `+` = "addition", stop("undefined") ) } fun(`+`) #[1] "addition"
Comments
Post a Comment