6

I am currently working on a package, let's say it is called myPack. I have a function called myFunc1 and another function called myFunc2, which looks something like that:

myFunc2 <- function(x, parallel = FALSE) { 
if(parallel) future::plan(future::multiprocess)
values <- furrr::future_map(x, myFunc1)
values
}

Now if I call myFunc2 while I'm not in parallel, it works. However if I call it with parallel = TRUE, I get the following error:

Error: Unexpected result (of class ‘snow-try-error’ != ‘FutureResult’)
retrieved for MultisessionFuture future (label = ‘<none>’, expression = 
‘{; do.call(function(...) {; ...future.f.env <- environment(...future.f); 
if (!is.null(...future.f.env$`~`)) {; if 
(is_bad_rlang_tilde(...future.f.env$`~`)) {; ...future.f.env$`~` <- 
base::`~`; ...; }); }, args = future.call.arguments); }’): there is no 
package called 'myPack'. This suggests that the communication with 
MultisessionFuture worker (‘SOCKnode’ #1) is out of sync.

Does anybody know why myFunc2 works in sequential mode, but not in parallel and how I can stop this error from appearing?

Reproducible example:

linear_model_1 <- lm(mpg ~ cyl + disp + hp, data = mtcars)
linear_model_2 <- lm(mpg ~ cyl + poly(disp, 2), data = mtcars)
x <- list(linear_model_1, linear_model_2)


myFunc1 <- function(model, seed, size) {
  `%>%` <- purrr::`%>%`
  set.seed(seed)
  draws <- rep(size, 10) %>% 
    furrr::future_map(sample, x = fitted(model), replace = TRUE)
  mean(unlist(draws))
}

(Note: This is not the entire function, but it's basically what it does in a shortened version)

1 Answers1

1

I had the same situation here. You have to install your package using devtools:install() at least once. This is documented in this issue: https://github.com/DavisVaughan/furrr/issues/95