DavisVaughan / furrr

Apply Mapping Functions in Parallel using Futures
https://furrr.futureverse.org/
Other
699 stars 40 forks source link

Issue with `bizdays` package options #183

Closed moneyhun closed 3 years ago

moneyhun commented 3 years ago

furrr family functions appear unable to access the options set in the bizdays package via bizdays.options$set(). The purrr family functions appear to access these options as expected.

See example below:

library(bizdays)
library(furrr)
library(purrr)
plan(multiprocess)

# Load Rmetrics calendars for 2020
load_rmetrics_calendars(2020)

# Set default calendar to NYSE
bizdays.options$set(default.calendar = "Rmetrics/NYSE")

# Define function to return bizdays options and list of holidays
options_holidays <- function(x) {
  out <- list(
    bizdays.options$get(), 
    holidays()
  )
}

# Run via purrr and furrr; 
via_furrr <- future_map(1, options_holidays)
via_purrr <- map(1, options_holidays)

# Print results
print(via_furrr)
print(via_purrr)

map returns the expected output; future_map indicates that Rmetrics/NYSE has not been set as the default calendar, and returns an empty list of holidays.

DavisVaughan commented 3 years ago

furrr is running your options_holidays() function in a completely separate R process and that R process doesn't know that you've set the default calendar to something else. You'll need to set the default calendar inside the options_holidays() function to get it to work. It isn't a bug, it is just something to be aware of when working with parallel code

moneyhun commented 3 years ago

Thanks, that makes sense!