1. Learn
  2. /
  3. Courses
  4. /
  5. Creating R Packages

Exercise

Testing warnings

You can use expect_warning() to test if the output of a function also returns a warning. If the function returns a warning, the test will pass, otherwise, it will fail. You can optionally define the warning message that should be returned to ensure that you are testing for the correct warning.

Your data_summary() function has been updated to issue a warning if na.rm is set to FALSE and if the data contains missing values.

Instructions

100 XP
  • Call data_summary() on airquality dataset with na.rm set to FALSE and see what happens.
  • Pick an appropriate expect_*() function such that when you call data_summary() on airquality with na.rm set to FALSE again, the test passes.