Warnings suppressed with mclapply in R

mclapply, r, warnings

Solution

According to `mclapply`'s help page, in my opinion the argument `mc.silent` should allow you to chose if warnings are to be printed or not. Strangely, it does not do that. Setting it explictly to `TRUE` or `FALSE` does not have any effect in your situation.

So that leaves us only with a somewhat dirty hack: forcing R to print warnings as they occur.

options(warn=1)
mclapply(1:3, function(x) warning(x))

# Warning in FUN(1L[[1L]], ...) : 1
# Warning in FUN(2L[[1L]], ...) : 2
# Warning in FUN(3L[[1L]], ...) : 3
# [[1]]
# [1] "1"
#
# [[2]]
# [1] "2"
#
# [[3]]
# [1] "3"

Problem

With `mclapply()` all issued warnings seems get suppressed: ``` library(multicore) mclapply(1:3, function(x) warning(x)) [[1]] [1] "1" [[2]] [1] "2" [[3]] [1] "3" ``` while `lapply` would give: ``` lapply(1:3, function(x) warning(x)) [[1]] [1] "1" [[2]] [1] "2" [[3]] [1] "3" Warning messages: 1: In FUN(1:3[[3L]], ...) : 1 2: In FUN(1:3[[3L]], ...) : 2 3: In FUN(1:3[[3L]], ...) : 3 ``` Any tips on how to avoid loosing the warnings?

Original source