Get startedGet started for free

Processing multiple inputs

You work as a Payroll Analyst for an outsourcing firm. Each month, you receive data for the workers on your payroll. You have been asked to write parallel R code that can calculate the total payout per day.

You have two lists in your workspace, ls_hours and ls_rates. Each has 30 elements, one for each day of the month. Each element of ls_hours is composed of the hours worked by each worker on a given day, and each element of ls_rates contains the corresponding hourly rates. You also have function, calc_payout(), that takes two arguments, hours and rates.

calc_payout <- function (hours, rates) paste0("$", sum(hours * rates))

You need to use the appropriate function from the furrr package to do this calculation in parallel. The furrr package has been loaded for you.

This exercise is part of the course

Parallel Programming in R

View Course

Exercise instructions

  • Use the future_map() variant that takes multiple inputs to loop over.
  • Combine ls_hours and ls_rates.
  • Specify the function calc_payout() to the future_map() variant.
  • Revert to a sequential plan.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

plan(multisession, workers = 5)

# Use the correct future_map() variant
___(
# Combine ls_hours and ls_rates
  ___(___, ___),
# Specify the function to apply
  ___)

# Revert to sequential plan
___(___)
Edit and Run Code