Created
January 10, 2022 23:55
-
-
Save jmbarbone/a35b5ac59ba21f45754c1e9a2ee3968b to your computer and use it in GitHub Desktop.
format cli args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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