시작하기무료로 시작하기

Check for warnings and errors

Another key part of test-driven package development is to ensure that errors and warnings are being outputted when we expect them to be. As someone that now has experience building and working with R functions, you understand that it is expected behavior for warnings and errors to appear if incorrect arguments were passed into the function. For example, the dist_converter() function in the unitConverter package is expected to produce a warning and also an error depending on the inputs to the function when it is called. We need to write expectations to ensure this behavior does occur when we expected it. Remember that expectations do not output anything if they were successful.

The testthat package and the unitConverter package at this point in development have been loaded for you.

이 연습은 강의의 일부입니다

Developing R Packages

강의 보기

연습 안내

  • Create an expectation showing that converting 25 feet to feet producing a warning.
  • Define an expectation showing that converting "cold" feet to meters produces an error.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Warning for feet to feet
___(dist_converter(___, "feet", "feet"))

# Error for cold feet
___(dist_converter("___", "feet", "meters"))
코드 편집 및 실행