HenrikBengtsson / doFuture

:rocket: R package: doFuture - Use Foreach to Parallelize via Future Framework
https://doFuture.futureverse.org
84 stars 6 forks source link

Error message when using package #28

Closed cegbuna closed 6 years ago

cegbuna commented 6 years ago

Hi,

Thanks for the package.

I'm getting the following error message when I run the example in the package

Example

library("doFuture")
registerDoFuture()
plan(multiprocess)

my_stat <- function(x) {
  median(x)
}

my_experiment <- function(n, mu = 0.0, sigma = 1.0) {
  foreach(i = 1:n) %dopar% {
    x <- rnorm(i, mean = mu, sd = sigma)
    list(mu = mean(x), sigma = sd(x), own = my_stat(x))
  }
}

y <- my_experiment(n = 3)
str(y)

Error message

Error in UseMethod("conditionMessage") : 
  no applicable method for 'conditionMessage' applied to an object of class "NULL"

Is there a reason why?

Thank you E

HenrikBengtsson commented 6 years ago

Thanks for reporting. I cannot reproduce this. What is your sessionInfo() and what does traceback() report immediately after you get that error?

cegbuna commented 6 years ago

Thanks for responding. The sessionInfo() and traceback() outputs are below.

sessionInfo

R version 3.4.3 (2017-11-30)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
[1] doSNOW_1.0.16     snow_0.4-2        doParallel_1.0.11 iterators_1.0.9   foreach_1.4.4     sp_1.2-7          RSQLite_2.0      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.15       magrittr_1.5       bit_1.1-12         xtable_1.8-2       lattice_0.20-35    R6_2.2.2           rlang_0.2.0        blob_1.1.0         tools_3.4.4        grid_3.4.4         DBI_0.8           
[12] htmltools_0.3.6    crosstalk_1.0.0    yaml_2.1.17        bit64_0.9-7        leaflet_1.1.0.9000 digest_0.6.15      tibble_1.4.2       shiny_1.0.5        codetools_0.2-15   htmlwidgets_1.0    memoise_1.1.0     
[23] mime_0.5           compiler_3.4.4     pillar_1.2.1       httpuv_1.3.6.2 

traceback

10: conditionMessage(e)
9: value[[3L]](cond)
8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
7: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({
       while (i < n) {
           if (i >= size) {
               size <- min(2 * size, n)
               length(a) <- size
           }
           a[i + 1] <- list(nextElem(x))
           i <- i + 1
       }
   }, error = function(e) {
       if (!identical(conditionMessage(e), "StopIteration")) 
           stop(e)
   })
5: as.list.iter(it)
4: as.list(it)
3: e$fun(obj, substitute(ex), parent.frame(), e$data)
2: foreach(i = 1:n) %dopar% {
       x <- rnorm(i, mean = mu, sd = sigma)
       list(mu = mean(x), sigma = sd(x), own = my_stat(x))
   } at #2
1: my_experiment(n = 3)
HenrikBengtsson commented 6 years ago

I don't see doFuture, future, ... in that session info - call sessionInfo() after you've attached doFuture. Also, there are lots of other packages loaded too. Please try to reproduce this in a fresh R session.

HenrikBengtsson commented 6 years ago

I see your https://stackoverflow.com/questions/51754452/r-foreach-package-returns-error-message post. It looks like you've resolved this by upgrading to R 3.4.4. I'm closing this one.