[R] Is it possible to recursively update a function?

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Mar 4 20:36:19 CET 2010

On 04.03.2010 20:08, Seeker wrote:
> Here is the test code.
> foo<-function(x) exp(-x)
> for (i in 1:5)
> {
> foo<-function(x) foo(x)*x
> foo(2)

Hmmm, wenn do you think does the evaluation stop? Your recursion has an 
infinity depth.
If you cannot get the recursion right (and even if you can): Try to get 
around without recursion, it is in most cases a bad idea in R: You are 
wasting memory and it is rather slow compared to iterative approaches.

Uwe Ligges

> }
> The error is "evalution nested too deeply". I tried Recall() but it
> didn't work either. Thanks a lot for your input.
> ______________________________________________
> 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.

More information about the R-help mailing list