3

The parallel package suppresses non-returned printing with parSapply and parLapply. Is it possible to bypass this effect?

Normal (with expected behavior)

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

Parallel process (unexpected suppression)

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)
Pierre L
  • 28,203
  • 6
  • 47
  • 69

1 Answers1

0

I'm not sure that this it is possible because of issues with parallel access to R terminal from separate processes forked by parallel

If you need to get messages from your processes then this SO answer should help (Briefly: use outfile param in parallel::makeCluster)

Community
  • 1
  • 1