我正在使用包parallel
进行计算。这是一个玩具示例:
library(parallel)
m = matrix(c(1,1,1,1,0.2,0.2,0.2,0.2), nrow=2)
myFun = function(x) {
if (any(x<0.5)) {
write("less than 0.5", stderr())
return(NA)
} else {
write("good", stdout())
return(mean(x))
}
}
cl = makeCluster(2, outfile="/tmp/output")
parApply(cl, m, 2, myFun)
stopCluster(cl)
问题是 stdout 和 stderr 都将被重定向到/tmp/output
. 该output
文件如下所示:
starting worker pid=51083 on localhost:11953 at 11:37:12.966
starting worker pid=51093 on localhost:11953 at 11:37:13.261
good
good
less than 0.5
less than 0.5
有没有办法分别为stdout和stderr设置两个单独的文件?以及如何忽略“starting worker pid = ...”的前两行?