I am trying to call a function with a given string of the function name.
E.g.
print(funcList)
[[1]]
`*`
[[2]]
sin
works:
mult <- `*`
mult(5,6)
[1] 30
doesn’t work:
func1 <- funcList[[1]]
func1(5,6)
func2 <- funcList[[2]]
func2(1.2)
So is it possible to call all of the functions in the functionList?
Those don’t look like strings; that looks like a list of functions. To answer the question posed in your title, see
get(). For example, using your list but stored as character strings:we can use
get()to return the function with name given by the selected element of the list:An alternative is the
match.fun()function, which given a string will find a function with name matching that string:but as
?match.funtells us, we probably shouldn’t be doing that at the prompt, but from within a function.If you do have a list of functions, then one can simply index into the list and use it as a function:
or you can save the functions out as interim objects, but there is little point in doing this: