[R] Parallel processing question ...

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Feb 9 17:39:20 CET 2011


Hi David,

I'm CC-ing R-help inorder to finish this one off ;-)

On Wed, Feb 9, 2011 at 10:59 AM, Robinson, David G <drobin at sandia.gov> wrote:
[snip]
> One of you comments pointed me in the right direction and I found the
> problem. I simply commented out the line " if (j%%100==0) { ...print(N)}"
> and the original program ran fine.  Not sure I understand why, but... it
> runs.
[/snip]

It's because the last line of a "block" or "function" or whatever is
the implicit return value of that block/function (as you already know
-- the last line of your `update_N` function is `N`, which means
that's the value you want that function to return).

The last line of your the "block" inside your %dopar% { ... } was in
if-statement and not the value `lambda` that you wanted to return.

As a result the return value of your block was the result of that
if-statement. Keep in mind that in R, even `if` statements return
values, eg:

x <- if (FALSE) {
  1
} else {
  2
}

In the case above, x will be set to 2.

Does that make it more clear now why your lambda vector wasn't being
returned (and further processed) after each iteration of your foreach
loop?

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list