Please help me to make my code work. Here I'm trying to create an S3 template which can take different formulas and numeric vectors as arguments. Also I want to add a plot method, drawing the resulting figure. For now it throws an error:
Error in do.call(f, list(x, y)) : 'what' must be a function or character string
How to correctly use do.call here?
# template
chart <- function(x, y, f, ...) {
list(x, y,
do.call(f, list(x, y)),
class = "myChart")
}
# plot method
plot.myChart <- function(obj, ...) {
persp(x, y, z = outer(x, y, f))
}
# new object
c <- chart(seq(-6, 6, length = 100),
seq(-6, 6, length = 100),
f=sqrt(x^2+y^2))
c
plot.myChart(c)