1. Learn
  2. /
  3. Courses
  4. /
  5. Parallel Programming in R

Exercise

The bootstrap error

You work as an R programmer for a clinical laboratory. The statistician at the lab is conducting a large scale analysis to establish ranges for the average weights of different species of mice. She has written a a function, bootstrap(), that is applied to every element of weight_list in parallel using a futures backend. However the code throws the following error:

Error in checkForRemoteErrors(val) : 
  one node produced an error: missing values and NaN's not allowed if 'na.rm' is FALSE

She cannot find the element of weight_list which causes the error. She also loses all results of the time-consuming calculation. You have been asked to fix the code. The furrr package has been loaded for you and the multisession for the futures has been planned.

Instructions

100 XP
  • Supply the code in the curly braces to a function that can catch the error.
  • To the error argument, supply a function that takes one argument, e, and returns the string "Error here!".
  • Map bootstrap() to all elements of the weight_list using a furrr function.