I am facing a strange problem about do.call and curve:
func1 <- function (m, n) {
charac <- paste ("func2 <- function(x)", m, "*x^", n, sep = "")
eval(parse(text = charac))
return(func2)
}
func3 <- function (m, n) {
my.func <- func1 (m, n)
do.call("curve",list(expr = substitute(my.func)))
}
func1 constructs func2 and func3 plots the constructed func2. But when I run func3, following error would be displayed:
> func3 (3, 6)
Error in curve(expr = function (x) :
'expr' must be a function, or a call or an expression containing 'x'
However, while I run func1 and plot the output manually (without applying func3), func2 would be plotted:
my.func <- func1 (3, 6)
do.call("curve",list(expr = substitute(my.func)))
What happened here leads me to a confusion and I do not know why do.call can not plot func2 inside func3 local environment.
Thank you