Skip to content

parRapply and parCapply return a list in corner cases

1 message · Simone Giannerini

#
According to ?parCapply:

parRapply and parCapply always return a vector.

This appears not to be the case in the following minimal reproducible example:
+         ind <- x[1]
+         y   <- x[-1]
+         if(ind==1){
+             r1 <- sum(y)
+         }else{
+             r1 <- logical(0)
+         }
+         return(unlist(as.numeric(c(ind,r1))))
+     })
[[1]]
[1] 1

[[2]]
[1] 6

[[3]]
[1] 1

[[4]]
[1] 6

[[5]]
[1] 0

[[6]]
[1] 1 6
[1] "list"
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C
[5] LC_TIME=Italian_Italy.1252

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets
methods   base

loaded via a namespace (and not attached):
[1] compiler_4.0.0