Skip to contents

Convenience function combining fn_param_defaults(), wrap_chr() and cli::ansi_collapse().

Usage

enum_fn_param_defaults(
  param,
  fn = sys.function(sys.parent()),
  env = parent.frame(),
  wrap = "`",
  sep2 = " or ",
  last = sep2,
  ...
)

Arguments

param

Parameter name. A character scalar.

fn

A function or a function name (searched for in env). See base::formals() for details.

env

Environment fn is defined in. See base::formals() for details.

wrap

Character sequence the default parameter values are to be wrapped in. A character vector or something coercible to.

sep2, last

Passed on to cli::ansi_collapse().

...

Further arguments passed on to cli::ansi_collapse().

Value

A character scalar.

Details

This function can be very convenient to avoid duplication in roxygen2 documentation by leveraging inline R code evaluation as follows:

#' @param some_param Some parameter. One of
#'   `r pal::enum_fn_param_defaults(param = "some_param", fn = "some_fn")`.
#'
some_fn <- function(some_param = c("a", "b", "c")) {
  some_param <- rlang::arg_match(some_param)
  ...
}

See also

Other package documentation functions: fn_param_defaults(), roxy_blocks(), roxy_obj(), roxy_tag_value(), roxy_to_md_links()

Examples

pal::enum_fn_param_defaults(param = ".name_repair",
                            fn = tibble::as_tibble) |>
  cat()
#> `"check_unique"`, `"unique"`, `"universal"` or `"minimal"`