Function argument documentation
When documenting a function, one crucial aspect to cover is its arguments. With roxygen2, you can achieve this using the @param tag, followed by the argument name and relevant details. You'll just document the first argument in the exercise here, but it is best practice to document each of your function arguments, so you should think about how to document the other two at a later time.
이 연습은 강의의 일부입니다
Developing R Packages
연습 안내
- Add an appropriate tag to document the first argument of the
dist_converter()function by adding the following details to this tag:A numerical distance value to be converted.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
#' Convert between distances
#'
#' Performs the conversion based on specified `unit_from` and `unit_to` values.
#'
# Add appropriate tag and details to document the first argument
___
dist_converter <- function(dist_value, unit_from, unit_to) {
if (unit_from == "feet" && unit_to == "meters") {
return(dist_value / 3.28)
} else if (unit_from == "meters" && unit_to == "feet") {
return(dist_value * 3.28)
} else if (unit_from == unit_to) {
warning("unit_from and unit_to are the same, returning dist_value")
return(dist_value)
} else {
stop("This function only supports conversions between feet and meters.")
}
}