[R] Fwd: Recall function: "evaluation nested too deeply: infinite recursion / options(expressions=)?"

jim holtman jholtman at gmail.com
Thu Feb 11 19:01:33 CET 2010


You might be impacted by FAQ 7.31.

Your statement      if(v == -.5)

might be suspect.  You might want to use 'all.equal'

On Thu, Feb 11, 2010 at 11:40 AM, Allan Clark <Allan.Clark at uct.ac.za> wrote:
> hello all
>
> i searched the archives and couldn't get a solution to the following question.
>
> i have the following function:
>
> F=function(z,v)
> {
>  if (v==-.5) return(1) else  return(2*v/z + 1/Recall(z,v-1))
> }
>
> and while testing whether it works (ie F(z,v) is approx =  besselK(z,1+v)/besselK(z,V). the recursion formula allows one to calculate besselK(z,1+v)/besselK(z,V) for large values of z ) i got the following error : "evaluation nested too deeply: infinite recursion / options(expressions=)?"
>
> i.e.
> zz=1
> nn=1000
>
> R=array(0,dim=nn)
> for (i in 1:nn)
> {
>  print(i)
>  R[i]=F(zz,-0.5+(i-1))
> }
> the error occurs when i==713
> but when one evaluates F(1,-.5+(713-1)) i get [1] 1423.001
> note also that if v starts getting large, evaluation of F also gives the error. e.g. F(1, 713.5)
>
> any help?
>
>
> seems like looping works nicely here
>
> F2=function(z,v)
> {
>  #check that the v is correct! ie -.5, .5, 3/2, 5/2, .....
>
>  if (v==-0.5)
>  {
>    return(1)
>  }else
>  {
>    ntimes = v+1.5
>    R=array(0,dim=ntimes)
>
>    R[1]=1
>    for (i in 2:ntimes)
>    {
>      R[i]= 2*v/z + 1/R[i-1]
>    }
>    return(R[ntimes])
>  }
> }
>
>
>
>
>
>
> Allan Clark
> ========
> Lecturer in Statistical Sciences Department
> University of Cape Town
> 7701 Rondebosch
> South Africa
> TEL (Office): +27-21-650-3228
> FAX: +27-21-650-4773
> http://web.uct.ac.za/depts/stats/aclark.htm
>
>
>
> Allan Clark
> ========
> Lecturer in Statistical Sciences Department
> University of Cape Town
> 7701 Rondebosch
> South Africa
> TEL (Office): +27-21-650-3228
> FAX: +27-21-650-4773
> http://web.uct.ac.za/depts/stats/aclark.htm
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list