The furrr configuration
You work for a public health consultancy. Your boss wants you to write parallel code to calculate different quantiles of the life expectancy distribution.
In your workspace, you have ls_exp, a list of vectors. Each element of this list is a vector of life expectancy estimates for every country. The calc_quant() function to calculate quantiles is available for you. This function takes two arguments, life_exp, the life expectancy vector, and quant, a static value for the quantile to be calculated. The value to be supplied to the second argument is stored as my_quant in your workspace.
You need to apply calc_quant() to each element of ls_exp using the furrr package.
furrr has been loaded for you.
Diese Übung ist Teil des Kurses
Parallel Programming in R
Anleitung zur Übung
- Create a configuration for
furrrfunctions to specifymy_quantas a global variable. - In the
future_map()call, mapcalc_quant()to every element ofls_exp. - Supply the exported global variable to the
quantargument ofcalc_quant(). - Supply the configuration created earlier to the
.optionsargument.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Create a configuration to export global variables
config <- ___(globals = "___")
plan(multisession, workers = 5)
# Specify input list and function to apply
future_map(___, ___,
# Supply exported value to quant argument
quant = ___,
# Specify configuration
.options = ___)
plan(sequential)