Reputation: 5403
In R, I have a function which takes the name of another function as a parameter. I've constructed an if-statement within the parent function to check if the input function name is the same as the name of an already existing function of the name strategy_function.
function_parent <- function(function_name){
if(function_name == strategy_function){...}
}
However, R does not appreciate this notation. Is using the name of a function in this way possible, and even if it is, is there a better way? This seems slightly sloppy.
Upvotes: 0
Views: 1204
Reputation: 5403
Using deparse(substitute(strategy_function))
in the comparison did the trick.
Upvotes: 1
Reputation: 109874
Try quotes around strategy_function
:
function_parent <- function(function_name){
if(function_name == "strategy_function"){...}
}
Upvotes: 3