[R-sig-hpc] foreach() with 'lapply'?

John Ramey johnramey at gmail.com
Thu Jul 21 20:23:43 CEST 2011


Zach,

I have been looking for something like that, and now that I've seen
your solution, it seems so obvious.

Nice job!

-- 
John A. Ramey, M.S.
Ph.D. Candidate
Department of Statistics
Baylor University
http://www.johnramey.net

On Thu, Jul 21, 2011 at 11:18 AM, Zachary Mayer <zach.mayer at gmail.com> wrote:
> I use this function as a 'no brainer' replacement for lapply:
>
> felapply <- function(X, FUN, ...) {
>    foreach(i=X) %dopar% {
>        FUN(i, ...)
>    }
> }
> x <- felapply(seq(1,10), sqrt)
> y <- lapply(seq(1,10), sqrt)
> all.equal(x,y)
>
>
>
> On Thu, Jul 21, 2011 at 1:27 PM, Megh Dal <megh700004 at yahoo.com> wrote:
>
>> Dear all, I was exploring the "dopar" mechanism in foreach package, however
>> it seems that "dopar" can be applied only in place of 'for' loop. Here my
>> question is: can it be used with 'lapply' construct?
>>
>> I have a big 'list' object and I am in some process to apply some complex
>> custom made function on each element of that 'list' object. I have dual core
>> windows vista system, and planning to break that list into 2 part of equal
>> length, then apply that function simultaneously using both cores.
>>
>> Can somebody throw some light how to achieve that?
>>
>> Thanks for your help,
>>
>> _______________________________________________
>> R-sig-hpc mailing list
>> R-sig-hpc at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>



More information about the R-sig-hpc mailing list