这是《R 语言编程艺术》一书的一个经典案例,记录在此,方便查阅。 首先修改 curve() 函数,使其能返回 x 和 y 的取值。 crv = function (expr, from = NULL, to = NULL, n = 101, add = FALSE, type = "l", xname = "x", xlab = xname, ylab = NULL, log = NULL, xlim = NULL, …) { sexpr <- substitute(expr) if (is.name(sexpr)) { expr <- call(as.character(sexpr), as.name(xname)) } else { if (!((is.call(sexpr) || is.expression(sexpr)) && xname %in% all.vars(sexpr))) stop(gettextf("‘expr’ must be a function, or a call or an expression containing ‘%s’", xname), domain = NA) …