filesstrings (version 2.0.1)

nice_nums: Make string numbers comply with alphabetical order

Description

If strings are numbered, their numbers may not comply with alphabetical order, i.e. "abc2" comes after "abc10" in alphabetical order. We might (for whatever reason) wish to change them such that they come in the order that we would like. This function alters the strings such that they comply with alphabetical order, so here "abc2" would be renamed to "abc02". It works on file names with more than one number in them e.g. "abc01def3" (a string with 2 numbers). All the file names that it works on must have the same number of numbers, and the non-number bits must be the same.

Usage

nice_nums(strings)

Arguments

strings

A vector of strings.

Examples

Run this code
# NOT RUN {
strings <- paste0("abc", 1:12)
strings
nice_nums(strings)

nice_nums(c("abc9def55", "abc10def7"))
nice_nums(c("01abc9def55", "5abc10def777", "99abc4def4"))

# }
# NOT RUN {
nice_nums(c("abc9def55", "abc10xyz7"))
# }

Run the code above in your browser using DataCamp Workspace