[R] Threads in R

Immanuel mane.desk at googlemail.com
Tue Aug 23 00:12:44 CEST 2011


Hello,

thanks for the input. Below is a small example, simpler then expected :)
  I'm just curious why I can't see any output from print(i).

----------------------
library(multicore)

f_long <- function() {
     for (i in 1:100000000){ a=i}
         print(i)
     return("finished")
}

p_long <- parallel(f_long() ,silent =FALSE    )
collect(p_long, wait=FALSE, 10)
# stops the execution since its not finished after 10sec
# on my machine anyway ;)


f_short <- function() {
     for (i in 1:10000){ a=i}
         print(i)
     return("finished")
}


p_short <- parallel(f_short() ,silent =FALSE    )
collect(p_short, wait=FALSE, 10)
# will retrieve the result (since it's fast)



More information about the R-help mailing list