[R] print and cat not working with parallelised functions?

Martin Ivanov tramni at abv.bg
Sat Dec 8 21:04:04 CET 2012


 Dear R Community,

I am running R version 2.15.2 with package parallel version 2.15.2.
The problem is that cat and print do not produce any output. Also assigning objects to the .GlobalEnv does not work. This makes it difficult for me to debug code. This can be seen from the
following minimal working example:

library(parallel)
fun2 <- function(x) {
b <<- x; # try to export the object to the workspace
print(x); # try to print x
}

fun1 <- function(d) {
 cl <- makeCluster(getOption("cl.cores", detectCores()));
 parSapply(cl=cl, X=seq_along(d), FUN=fun2);
 stopCluster(cl=cl);
}
fun3 <- function(d) sapply(X=seq_along(d), FUN=fun2); 
fun1(d=1:5)
a <- fun3(d=1:5)

print only works when fun3 is called, that is when there is no parallelisation. The
same is also true for the <<- assignment.
I am almost sure this is not a bug, but a feature, so I would like to ask you
for some explanation and also for some ideas how to handle debugging code when 
no printing or exporting objects to the workspace works.

Any suggestions will be appreciated.

Best regards,

Martin Ivanov



More information about the R-help mailing list