Dear List members, I really, like the feature that one can call R functions with mathematical expressions, e.g.
curve(x^2, 0, 1) I wonder, how I can construct in a simple way a function like mycurve = function (expr) {...} such that that a call mycurve(x^2) has the same effect as the call curve(x^2, -100,100) Below is some code that works, but it seems much to complicated: it first substitutes and deparses the expression, creates a string with the new function call and then parses and evaluates the string again. Does anybody know a simpler, more elegant solution? mycurve = function(expr) { # The following attempt does not work # curve(substitute(expr),-100,100) # Transform original expression to a string org.expr = deparse(substitute(expr)) # Construct a string, parse it and evaluates it eval(parse(text=paste("curve(",org.expr,",-100,100)",sep=""))) } mycurve(x^2) Best regards, Sebastian [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.