fn_param_defaults | R Documentation |
Extracts a function parameter's default value(s) from its language definition and returns the result as a character vector.
fn_param_defaults(param, fn = sys.function(sys.parent()), env = parent.frame())
param |
Parameter name. A character scalar. |
fn |
A function or a function name (searched for in |
env |
Environment |
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::fn_param_defaults(param = "some_param", fn = "some_fn") |> pal::wrap_chr("\x60") |> cli::ansi_collapse()`. #' some_fn <- function(some_param = c("a", "b", "c")) { some_param <- rlang::arg_match(some_param) ... }
Or to list the possible parameter values formatted as an unnumbered list instead, replace cli::ansi_collapse()
with as_md_list()
in the example
above.
A character vector.
base::deparse1()
is used internally to get a character representation of non-character default values. Therefore all of deparse()
's fuzziness also
applies to this function.
Other package documentation functions:
enum_fn_param_defaults()
,
roxy_blocks()
,
roxy_obj()
,
roxy_tag_value()
,
roxy_to_md_links()
pal::fn_param_defaults(param = ".name_repair",
fn = tibble::as_tibble)
# as Markdown-formatted enumeration in prose
pal::fn_param_defaults(param = ".name_repair",
fn = tibble::as_tibble) |>
pal::wrap_chr("`") |>
cli::ansi_collapse() |>
cat()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.