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.
This exercise is part of the course
Parallel Programming in R
Exercise instructions
- Create a configuration for
furrr
functions to specifymy_quant
as a global variable. - In the
future_map()
call, mapcalc_quant()
to every element ofls_exp
. - Supply the exported global variable to the
quant
argument ofcalc_quant()
. - Supply the configuration created earlier to the
.options
argument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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)