2016-06-21 62 views
3

parallel包通過parSapply和和parLapply抑制非返回打印。可以繞過這種效果嗎?如何刪除打印抑制 - 並行包

正常(與預期的行爲)

sapply(iris, function(x) { 
    print("x") 
    message("message") 
    warning("warning") 
    return(x[2]) 
}) 
# [1] "x" 
# message 
# [1] "x" 
# message 
# [1] "x" 
# message 
# [1] "x" 
# message 
# [1] "x" 
# message 
# Sepal.Length Sepal.Width Petal.Length Petal.Width  Species 
#   4.9   3.0   1.4   0.2   1.0 
# Warning messages: 
# 1: In FUN(X[[i]], ...) : warning 
# 2: In FUN(X[[i]], ...) : warning 
# 3: In FUN(X[[i]], ...) : warning 
# 4: In FUN(X[[i]], ...) : warning 
# 5: In FUN(X[[i]], ...) : warning 

並行處理(突發抑制)

library(parallel) 
cl <- makeCluster(3) 
parSapply(cl, iris, function(x) { 
    print("x") 
    message("message") 
    warning("warning") 
    return(x[2]) 
}) 
# Sepal.Length Sepal.Width Petal.Length Petal.Width  Species 
#   4.9   3.0   1.4   0.2   1.0 

#Run after 
stopCluster(cl) 

回答