Your draw.graph function draw.graph missing an argument. Why not just use the return value of the function as an argument to the next function?
draw.graph <- function(y) { plot(seq_along(y), y) } method1 <- function(n) { return(runif(n, min=0, max=1.7)) } draw.graph(method1(100))
If you really need a function as an argument, you can try the following (please read ?match.fun ):
#
EDIT: To fulfill the OP question / comments, I add this specific example:
q1.func <- function(x) { num <- cos(30.2 * sqrt(x))^2 denom <- x^0.7 * exp(0.9*x) return(num/denom) } method1 <- function(n) { x <- runif(n, min=0, max=1.7) return(1.7*sum(1/n*q1.func(x))) } draw.graph <- function(n, fun) { fun <- match.fun(fun) y <- unlist(lapply(n, fun)) plot(n, y) } draw.graph(1:1000, method1)

source share