tags:

views:

99

answers:

1

Good afternoon,

Somebody asked me a question today and neither did I know the answer nor could I find it in the documentation.

This person simply asked me if the sapply function in R was making concurrent calls to the function you want to apply to the list, or if the computation is done sequantially.

Does anybody know the answer?

What about rapply (the recursive version of this function)?

Thanks,

Jeremie

+3  A: 

I believe the function is executing sequentially. If you want a parallelized version [of lapply()], you can check out mclapply() in the multicore package.

Stephen
Thanks for the link it's useful.But we still are not really SURE that a sequential execution is guaranteed right?
JSmaga
What version of 'sure' do you need? There is *source code* that gives you an idea.
Dirk Eddelbuettel
JSmaga, do you *need* the code to be sequential? That is, will the code not run the way you want it if it runs in a different order? That's a good sign that your code should be rewritten! You'd really be better off if the function was fully reentrant and purely functional...
Harlan
That was just for general information.By the way, if I wanted to do something sequential, I would write a recursive function handling the list element by element. Not sure it's optimal to concatenate evaluations in R though.Hence knowing that sapply if sequential is quite useful.
JSmaga