The free variables in a proto method are looked up in the object that the method was defined in so by referencing predict within test$predict you are referring back to test$predict whereas you mean to refer to stats::predict. Change the line that calls predict to:
stats::predict(.$spline(), x.fine) On Sun, Dec 20, 2009 at 11:49 AM, baptiste auguie <baptiste.aug...@googlemail.com> wrote: > Dear list, > > I made the following example of a proto object that contains some data > and a spline interpolation. I don't understand why test$predict() > fails with this error message: > > Error: evaluation nested too deeply: infinite recursion / > options(expressions=)? > > Best regards, > > baptiste > > test <- proto(source = data.frame(x=1:10, y=rnorm(10)), > raw = function(.){ > data.frame(xx=.$source$x, yy=.$source$y) > }, > spline = function(.){ > with(.$raw(), smooth.spline(xx, yy)) > }, > predict = function(., range=NULL, n=100){ > if(is.null(range)) > range <- range(.$raw()$xx) > > x.fine <- seq(from=range[1], to=range[2], length=n) > > predict(.$spline(), x.fine) > > } > ) > > test$source > test$raw() > test$spline() # OK so far > test$predict() # fails > > sessionInfo() > R version 2.10.1 RC (2009-12-06 r50690) > i386-apple-darwin9.8.0 > > locale: > [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 > > attached base packages: > [1] grid tools stats graphics grDevices utils datasets > [8] methods base > > other attached packages: > [1] lattice_0.17-26 ggplot2_0.8.5 digest_0.4.1 reshape_0.8.3 > [5] plyr_0.1.9 proto_0.3-8 constants_1.0 gtools_2.6.1 > > ______________________________________________ > 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. > ______________________________________________ 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.