Well, the problem is that curve() does not evaluate the parameter you pass. It looks at what you passed to the parameter, not the results of evaluating the parameter. When you run
curve(fn)
what you are going through is a βnameβ (or βsymbolβ). This forces the function to find a function with this name. When you run
curve(get("f1")) #error
You transferred the call. Again, this call is not made by a curve to see that it returns a function. As the error message says, if you pass the call, this expression should contain x . for instance
curve(f1(x))
is an example of the syntax of a call with the variable x .
If you really need to specify the function as a character vector, you can convert the character to a name object, and then construct a curve call using do.call. for instance
do.call("curve",list(as.name(fn)))
or you can change your call to call the resulting function using the special variable x
curve(get(fn)(x))
source share