1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Writing Functions in R

Connected

Exercise

Fixing function arguments

The harmonic mean function is almost complete. However, you still need to provide some checks on the na.rm argument. This time, rather than throwing errors when the input is in an incorrect form, you are going to try to fix it.

na.rm should be a logical vector with one element (that is, TRUE, or FALSE).

The assertive package is loaded for you.

Instructions

100 XP
  • Update calc_harmonic_mean() to fix the na.rm argument by using use_first() to select the first na.rm element, and coerce_to() to change it to logical.