R/utils.R

Defines functions enum

Documented in enum

#' Enumerate values
#'
#' Format a vector of values into a string that can be embedded into
#' messages conveyed to the user.
#'
#' @name enum
#'
#' @param x `[any]`
#'
#'   An object, typically an [atomic vector][base::atomic()].
#'
#' @returns A `character(1)` equal to `"x[[1]], x[[2]], ... or x[[length(x)]]"`,
#'   where `x` elements are replaced by their proper values.
#'
#' @details The actual output must be passed to another [`ui_*()`][dotprofile-ui]
#'   or \pkg{cli}'s function in order to be properly rendered. See examples.
#'
#' @examples
#' \dontrun{
#'   values <- c("a", "b", "c")
#'   dotprofile:::enum(values)
#'
#'   ## Render the output.
#'   dotprofile::ui_info("{.val {enum(values)}}")
#'   cli::cli_text("{.val {enum(values)}}")}
#'
#' @keywords internal
enum <- function(x)
{
    return(cli::cli_vec(x, list(vec_sep = ', ', vec_last = ' or ')))
}
jeanmathieupotvin/dotprofile documentation built on Dec. 20, 2021, 10:08 p.m.