เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Run a test on function examples

It is best practice to include examples for users of your package and its functions in the help documentation. This allows you to validate the behavior and correctness of the function against a set of predefined examples or test cases.

The following examples have been added to the roxygen2 heading for dist_converter():

#' @examples
#' # Meters to feet
#' dist_converter(4, "meters", "feet")
#' # Feet to meters
#' dist_converter(10.5, "feet", "meters")
#' \dontrun{
#' # Feet to feet (gives warning)
#' dist_converter(100, "feet", "feet")
#' # Non-numeric `dist_value` gives error
#' dist_converter("short", "feet", "meters")
#' }

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

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Developing R Packages

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Run a test on the function examples given with the dist_converter() function.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Test dist_converter() examples
___
แก้ไขและรันโค้ด