[R] Function question

Henrique Dallazuanna wwwhsd at gmail.com
Fri Sep 25 23:22:31 CEST 2009


Try this:

foo <- function(expr, x){
	eval(substitute(expr))
}

foo(x^2, 4)
foo(x^3-10, 2)

On Fri, Sep 25, 2009 at 6:16 PM, njhuang86 <njhuang86 at yahoo.com> wrote:
>
> Hi. I was wondering how I can write a function that generates the outcome
> values for a user specified equation. For example, function(x^2, 4) will
> return back 16 and function(x^3 - 10, 2) will give back -2...
>
> I've been playing around with various lines of code but somehow, I just
> cannot get R to recognize the equation that I pass to it is just a random
> variable and doesn't need to be initialized...
> --
> View this message in context: http://www.nabble.com/Function-question-tp25619434p25619434.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list