Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Created January 10, 2022 23:55
Show Gist options
  • Save jmbarbone/a35b5ac59ba21f45754c1e9a2ee3968b to your computer and use it in GitHub Desktop.
Save jmbarbone/a35b5ac59ba21f45754c1e9a2ee3968b to your computer and use it in GitHub Desktop.
format cli args
cli_args <- function(...) {
x <- list(...)
nm <- names(x)
stopifnot(all(nm != ""))
single <- nchar(nm) == 1L
nm[single] <- paste0("-", nm[single])
nm[!single] <- paste0("--", gsub("[[:punct:][:space:]]", "-", nm[!single]))
paste(nm, x, collapse = " ")
}
cli_args(a = "this", b = "that", longer_thing = 2)
#> [1] "-a this -b that --longer-thing 2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment