Error in future_map: argument ".f" is missing, with no default

Hi @landRower,

When using any of the {purrr} or {furrr} map functions, you have three choices for supplying the function (i.e. .f).

Let's assume we have one list/vector we are iterating over called x and we are using the function foo on each item:

  • If x is being passed to the function in the first argument position you can simply use map(x, foo). You can pass non-varying arguments into the ... of map, such as map(x, foo, other_arg = 'value')
  • If x is being passed on to any other argument position, we can use the formula notation with the .x placeholder like map(x, ~ foo(first = something, second = .x)
  • Lastly, we can use an anonymous function which takes x as its first argument: map(x, function(x) foo(x))

Okay, with that out of the way, future_map_dfr requires two arguments, .x and .f. You seem to only be passing in .x as future_map_dfr(tune_race_anova(...)) code.

Assuming you are iterating over xgb_earlystop_wf, something like this is syntactically correct code (though I don't think it will run, see below):

race_rs <-  future_map_dfr(
  .x = xgb_earlystop_wf,
  .f = ~ tune_race_anova(
    object = .x,
    resamples     = cv_folds,
    metrics       = xgb_metrics,
    grid          = stopping_grid,
    control       = control_race(
      verbose       = TRUE,
      verbose_elim  = TRUE,
      allow_par     = TRUE,
      parallel_over = 'everything'
    )
  ),
  .progress = T,
  .options = furrr_options(packages = "parsnip"),
)

As someone who uses the tidymodels ecosystem a lot, I am not sure what exactly you are trying to achieve with the above code. I think you only need to use this code on its own:

tune_race_anova(
    xgb_earlystop_wf,
    resamples     = cv_folds,
    metrics       = xgb_metrics,
    grid          = stopping_grid,
    control       = control_race(
      verbose       = TRUE,
      verbose_elim  = TRUE,
      allow_par     = TRUE,
      parallel_over = 'everything'
    )
  )

The parallelization happens internally, you do not need to use furrr/future to do manual parallel computation.

2 Likes