{"action":"created","issue":{"url":"https://api.github.com/repos/psolymos/pbapply/issues/35","repository_url":"https://api.github.com/repos/psolymos/pbapply","labels_url":"https://api.github.com/repos/psolymos/pbapply/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/psolymos/pbapply/issues/35/comments","events_url":"https://api.github.com/repos/psolymos/pbapply/issues/35/events","html_url":"https://github.com/psolymos/pbapply/issues/35","id":314168464,"number":35,"title":"pblapply() silently produces NULL while lapply() succeeds","user":{"login":"dashaub","id":7352649,"avatar_url":"https://avatars0.githubusercontent.com/u/7352649?v=4","gravatar_id":"","url":"https://api.github.com/users/dashaub","html_url":"https://github.com/dashaub","followers_url":"https://api.github.com/users/dashaub/followers","following_url":"https://api.github.com/users/dashaub/following{/other_user}","gists_url":"https://api.github.com/users/dashaub/gists{/gist_id}","starred_url":"https://api.github.com/users/dashaub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dashaub/subscriptions","organizations_url":"https://api.github.com/users/dashaub/orgs","repos_url":"https://api.github.com/users/dashaub/repos","events_url":"https://api.github.com/users/dashaub/events{/privacy}","received_events_url":"https://api.github.com/users/dashaub/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-13T16:15:31Z","updated_at":"2018-04-13T17:29:40Z","closed_at":null,"author_association":"NONE","body":"Apologies that this is neither minimal nor fully reproducible, but it is at least an example.\r\n\r\n## Setup\r\n[dat.gz](https://github.com/psolymos/pbapply/files/1905021/dat.gz)\r\nThis is running on R 3.4.4 (built from source) inside a Docker container on Debian Stretch from the [Rocker images](https://hub.docker.com/r/rocker/r-ver/):\r\n```\r\n> sessionInfo()\r\nR version 3.4.4 (2018-03-15)\r\nPlatform: x86_64-pc-linux-gnu (64-bit)\r\nRunning under: Debian GNU/Linux 9 (stretch)\r\n\r\nMatrix products: default\r\nBLAS: /usr/lib/openblas-base/libblas.so.3\r\nLAPACK: /usr/lib/libopenblasp-r0.2.19.so\r\n\r\nlocale:\r\n [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              \r\n [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    \r\n [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             \r\n [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 \r\n [9] LC_ADDRESS=C               LC_TELEPHONE=C            \r\n[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       \r\n\r\nattached base packages:\r\n[1] stats     graphics  grDevices utils     datasets  methods   base     \r\n\r\nother attached packages:\r\n[1] data.table_1.10.4-3   pbapply_1.3-4         forecastHybrid_2.2.12\r\n[4] thief_0.3             forecast_8.3         \r\n\r\nloaded via a namespace (and not attached):\r\n [1] Rcpp_0.12.16      magrittr_1.5      doParallel_1.0.11 uroot_2.0-9      \r\n [5] munsell_0.4.3     colorspace_1.3-2  lattice_0.20-35   rlang_0.2.0      \r\n [9] quadprog_1.5-5    foreach_1.4.4     TTR_0.23-3        plyr_1.8.4       \r\n[13] tools_3.4.4       xts_0.10-2        nnet_7.3-12       parallel_3.4.4   \r\n[17] quantmod_0.4-12   grid_3.4.4        nlme_3.1-137      timeDate_3043.102\r\n[21] gtable_0.2.0      urca_1.3-0        iterators_1.0.9   tseries_0.10-43  \r\n[25] lazyeval_0.2.1    lmtest_0.9-36     tibble_1.4.2      ggplot2_2.2.1    \r\n[29] codetools_0.2-15  curl_3.2          fracdiff_1.4-2    compiler_3.4.4   \r\n[33] pillar_1.2.1      scales_0.5.0      zoo_1.8-1   \r\n```\r\n\r\nI was also _not_ able to reproduce this behavior with R 3.4.4 on OSX, and I've tried setting `numCores <- 1` inside the Docker container and everything seems to work. Here are the minimal sets of packages necessary to reproduce the bug:\r\n```\r\ndevtools::install_github(\"robjhyndman/forecast\", ref = \"0b10c5327cbbdadeb7fee23c44b1278b68f078de\")\r\ndevtools::install_github(\"ellisp/forecastHybrid/pkg\", ref = \"c928178a43ed43d457d86230a2edd8f3b57cf61c\")\r\nload(\"dat.gz\")\r\nseriesHorizon <- 18\r\nlibrary(forecastHybrid)\r\nlibrary(pbapply)\r\n\r\n> names(dat)\r\n [1] \"M19567\" \"M45556\" \"M12971\" \"M24651\" \"M46624\" \"M17619\" \"M14794\" \"M1631\" \r\n [9] \"M31812\" \"M43884\" \"M2144\"  \"M9584\"  \"M35428\" \"M6221\"  \"M33777\" \"M47591\"\r\n[17] \"M44973\" \"M28249\" \"M34842\" \"M23189\"\r\n```\r\n\r\n## Bug report\r\n\r\nThe seeds really should not be necessary since all of the functions are deterministic, but I set them anyway.\r\nA regular for loop produces expected results where all objects are of class \"forecast\":\r\n```\r\n> set.seed(40)\r\n> forecasts <- list()\r\n> for(i in seq_along(dat)){\r\n      forecasts[[i]] <- forecast(hybridModel(y = x, models = \"aft\", verbose = FALSE),\r\n                                 h = seriesHorizon, level = 95,\r\n                                 PI.combination = \"mean\")\r\n }\r\n> table(sapply(forecasts, class))\r\n\r\nforecast \r\n      20 \r\n> which(sapply(forecasts, is.null))\r\ninteger(0)\r\n```\r\n\r\nEverything still works when using `lapply`:\r\n```\r\n> set.seed(40)\r\n\r\n> forecasts <- lapply(dat, FUN = function(x) forecast(hybridModel(y = x, models = \"aft\",\r\n                                                                  verbose = FALSE),\r\n                                                      h = seriesHorizon, level = 95,\r\n                                                      PI.combination = \"mean\"))\r\n> table(sapply(forecasts, class))\r\n\r\nforecast \r\n      20 \r\n> which(sapply(forecasts, is.null))\r\nnamed integer(0)\r\n```\r\n\r\nHowever, with `pblapply()` some of the jobs fail silently.\r\n```\r\n> set.seed(40)\r\n> numCores <- 6\r\n> forecasts <- pblapply(dat,\r\n                        FUN = function(x) forecast(hybridModel(y = x, models = \"aft\",\r\n                                                               verbose = FALSE),\r\n                                                   h = seriesHorizon, level = 95,\r\n                                                   PI.combination = \"mean\"),\r\n                        cl = numCores)\r\n\r\n> table(sapply(forecasts, class))\r\n\r\nforecast     NULL \r\n      19        1 \r\n> which(sapply(forecasts, is.null))\r\nM17619 \r\n     6 \r\n```\r\n\r\nAnd once more. There are failures again, but they do not reproduce the earlier results.\r\n```\r\nset.seed(40)\r\nnumCores <- 6\r\nforecasts <- pblapply(dat,\r\n                      FUN = function(x) forecast(hybridModel(y = x, models = \"aft\",\r\n                                                             verbose = FALSE),\r\n                                                 h = seriesHorizon, level = 95,\r\n                                                 PI.combination = \"mean\"),\r\n                      cl = numCores)\r\n> table(sapply(forecasts, class))\r\n\r\nforecast     NULL \r\n      18        2 \r\n> which(sapply(forecasts, is.null))\r\nM17619 M35428 \r\n     6     13 \r\n```\r\n\r\nI can keep running the process with `pblapply()` and get different failures each time.\r\n"},"comment":{"url":"https://api.github.com/repos/psolymos/pbapply/issues/comments/381206537","html_url":"https://github.com/psolymos/pbapply/issues/35#issuecomment-381206537","issue_url":"https://api.github.com/repos/psolymos/pbapply/issues/35","id":381206537,"user":{"login":"psolymos","id":831636,"avatar_url":"https://avatars0.githubusercontent.com/u/831636?v=4","gravatar_id":"","url":"https://api.github.com/users/psolymos","html_url":"https://github.com/psolymos","followers_url":"https://api.github.com/users/psolymos/followers","following_url":"https://api.github.com/users/psolymos/following{/other_user}","gists_url":"https://api.github.com/users/psolymos/gists{/gist_id}","starred_url":"https://api.github.com/users/psolymos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psolymos/subscriptions","organizations_url":"https://api.github.com/users/psolymos/orgs","repos_url":"https://api.github.com/users/psolymos/repos","events_url":"https://api.github.com/users/psolymos/events{/privacy}","received_events_url":"https://api.github.com/users/psolymos/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T17:29:40Z","updated_at":"2018-04-13T17:29:40Z","author_association":"OWNER","body":"Can you try with Socket cluster? It worked on Windows with R 3.3.3:\r\n\r\n```R\r\nlibrary(parallel)\r\ncl <- makeCluster(6)\r\nclusterEvalQ(cl,library(forecastHybrid))\r\nclusterEvalQ(cl,seriesHorizon <- 18)\r\nforecasts <- pblapply(dat,\r\n                        FUN = function(x) forecast(hybridModel(y = x, models = \"aft\",\r\n                                                   verbose = FALSE),\r\n                                                   h = seriesHorizon, level = 95,\r\n                                                   PI.combination = \"mean\"),\r\n                        cl = cl)\r\nstopCluster(cl)\r\ntable(sapply(forecasts, class))\r\n# forecast \r\n#      20 \r\n```\r\n\r\nOr see if  `parallel::mclapply` gives you the same issue:\r\n\r\n```R\r\nnumCores <- 6\r\nforecasts <- parallel::mclapply(dat,\r\n                      FUN = function(x) forecast(hybridModel(y = x, models = \"aft\",\r\n                                                 verbose = FALSE),\r\n                                                 h = seriesHorizon, level = 95,\r\n                                                 PI.combination = \"mean\"),\r\n                      mc.cores = numCores)\r\n```"}}
{"actor":{"display_login":"psolymos"}}