LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • Create a configuration for furrr functions to specify my_quant as a global variable.
  • In the future_map() call, map calc_quant() to every element of ls_exp.
  • Supply the exported global variable to the quant argument of calc_quant().
  • Supply the configuration created earlier to the .options argument.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen