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.
Este exercício faz parte do curso
Developing R Packages
Instruções do exercício
- 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
#' 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.")
}
}