BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Developing R Packages

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

#' 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.")
  }
}
Kodu Düzenle ve Çalıştır