random_names | R Documentation |
Create unique names for objects, files, etc. that are guaranteed to not already exist.
random_names(
n_random_names = 1L,
exclude_names = character(0L),
name_length = 10L,
character_pool = letters,
transform = identity,
n_max_tries = 1000L
)
n_random_names |
generate this many random names |
exclude_names |
|
name_length |
length of each random name |
character_pool |
vector of characters (each must be a string of length one) to sample from
when generating random names; the first character in any random name is
always generated from |
transform |
this transformation is applied first before checking whether
they already exist in |
n_max_tries |
sampling of an individual random name is attempted this many times before giving up (raising an error); one may need to give if for some reason there are so many names to avoid or the pool of characters is so small that no random name can be generated |
# avoiding writing over a pre-existing file
random_names(exclude_names = "my_file.csv",
transform = function(x) paste0(x, ".csv"))
# avoiding writing over a pre-existing file path
random_names(exclude_names = "path/to/my_file.csv",
transform = function(x) paste0("path/to/", x, ".csv"))
# avoiding writing over a pre-existing file path for multiple files
random_names(n_random_names = 10L,
exclude_names = "path/to/my_file.csv",
transform = function(x) paste0("path/to/", x, ".csv"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.