r - How can I print when using %dopar% -


i have foreach loop uses %dopar% dosnow back-end. how can have loop print out each iteration?

my code below i'm using, not printing anything.

foreach(ntree=rep(25,2),.combine=combine,.packages='randomforest',     .inorder=false) %dopar% {         print("random forest")         randomforest(classform,data=data,na.action=na.action,do.trace=do.trace,ntree=ntree,mtry=mtry)     }    

there number of solutions posted here, find easiest log socket , use separate process output log calls in console.

i use following function:

log.socket <- make.socket(port=4000)  log <- function(text, ...) {   msg <- sprintf(paste0(as.character(sys.time()), ": ", text, "\n"), ...)   cat(msg)   write.socket(log.socket, msg) } 

you can place log statements in code such as:

log("processing block %d of %d", i, n.blocks) 

log output can viewed in real-time using simple socket listening tool. example, using netcat on linux:

nc -l 4000 

the above log statement display in netcat terminal as:

2014-06-25 12:30:45: processing block 2 of 13 

this method has advantage of working remotely , provides detailed output care log.

p.s. on windows, see jon craton's netcat port.

p.p.s i'm guessing write.socket r function isn't thread-safe, unless you're logging @ high frequency, you're unlikely run issue. aware of though.


Comments