Automatically generate names for vectors

autonames(x, ..., trimws = getRversion() > numeric_version("3.3.0"))

Arguments

x

A vector

...

Additional arguments passed to format()

trimws

Whether to trim whitespace surrounding automatically formatted names. Requires R version 3.3.0 or greater. Defaults to TRUE if R version is 3.3.0 or greater.

Value

Returns the names of a named vector and the elements of an unnamed vector formatted as characters.

Examples

autonames(c(a = "apple", b = "banana", c = "cantaloupe"))
#> [1] "a" "b" "c"
autonames(c("apple", "banana", "cantaloupe"))
#> [1] "apple" "banana" "cantaloupe"
autonames(10^(1:4))
#> [1] "10" "100" "1000" "10000"
autonames(10^(1:4), big.mark = ",")
#> [1] "10" "100" "1,000" "10,000"
autonames(10^(1:4), scientific = TRUE)
#> [1] "1e+01" "1e+02" "1e+03" "1e+04"