Re: [R] How can I access the list argument within a "for" function call

From: Mike Rowe <mwrowe_at_gmail.com>
Date: Sun, 23 Nov 2008 18:30:52 -0800 (PST)

I'm sorry if I wasn't clear before...

Although it is hidden syntactically, a for-loop construct is implemented
by a call to the "for" function:

"for"(var, list, expr)

...where var is the iteration variable, list is the sequence of values
assigned to var on successive iterations, and expr is the statement or
statements inside the body of the loop that get executed. For example,
you can recast:

for(X in 1:10) print(x)

as:

"for"(x,1:10,print(x))

When "inside" other functions, I can get their arguments using sys.call (1).
Calls to the for function do not seem to create a new frame though, so this
doesn't work. What I want to know is how to retrieve the list argument
from within the loop.

Thanks!
Mike

On Nov 22, 7:03 am, "jim holtman" <jholt..._at_gmail.com> wrote:
> I am not sure exactly what you mean with your question.  If you have a
> named list and want to access the 'name' within the 'for' along with
> the value, then you can do something like this:
>
> for (i in names(myList)){
>     value <- myList[[i]]   # get the values
>     plot(values, main=paste("Plot of", i))
>
> }
>
> A little more clarification is need on your question.
>
>
>
> On Fri, Nov 21, 2008 at 3:30 PM, MikeRowe<mi..._at_tethysbio.com> wrote:
> > Greetings,
>
> > I have been playing around with the R/Parallel package, which can farm out the computation of a for-loop among multiple worker processes.  Each worker gets a chunk of the for-loop iterations; for example, if you have two workers and for(x in 1:1000){...}, one worker would typically get iterations 1:500, while the second does 501:1000.
>
> > I would like to be able to preallocate matrices to capture the results within the for loop, on the first iteration.  Is there a way to access the list argument of the "for" function programmatically from within the loop?  I am referring to the for arguments shown on page 51 of the R Language Definition manual:
>
> >   "for"(var,list,expr)
>
> > I think I have a work-around, but was curious whether this was possible...
>
> > Thanks,
> > Mike
>
> >        [[alternative HTML version deleted]]
>
> > ______________________________________________
> > R-h..._at_r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guidehttp://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?
>
> ______________________________________________
> R-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



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. Received on Mon 24 Nov 2008 - 02:45:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 25 Nov 2008 - 08:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive