[R] Iteration idioms & laziness
David Duffy
David.Duffy at qimr.edu.au
Mon Nov 30 05:24:10 CET 2009
Duncan Murdoch murdoch at stats.uwo.ca wrote:
>
> > On 27/11/2009 3:36 PM, Alexander Søndergaard wrote:
> > I'm new to R. Having a functional background, I was wondering what's
> > the idiomatic way to iterate. It seems that for loops are the default
> > given there's no tail-call optimization.
> >
> > I'm curious to know whether there is a way to transform the following
> > toy snippet into something that doesn't eat up gigabytes of memory
> > (like it's for loop counterpart) using laziness:
> >
> > Reduce('+', seq(1,1e6))
>
> I believe the iterators and foreach packages give ways to iterate
> without creating the whole array, so they might do what you want.
The OP may also be interested in the jit package, which currently
just covers (see http://www.milbo.users.sonic.net/ra) loops, but
might eventually extend to TCO.
David Duffy.
--
| David Duffy (MBBS PhD) ,-_|\
| email: davidD at qimr.edu.au ph: INT+61+7+3362-0217 fax: -0101 / *
| Epidemiology Unit, Queensland Institute of Medical Research \_,-._/
| 300 Herston Rd, Brisbane, Queensland 4029, Australia GPG 4D0B994A v
More information about the R-help
mailing list