strex (version 1.2.0)

str_alphord_nums: Make string numbers comply with alphabetical order.

Description

If strings are numbered, their numbers may not comply with alphabetical order, e.g. "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 strings in the character vector string must have the same number of numbers, and the non-number bits must be the same.

Usage

str_alphord_nums(string)

Arguments

string

A character vector.

Value

A character vector.

Examples

Run this code
# NOT RUN {
string <- paste0("abc", 1:12)
print(string)
str_alphord_nums(string)
str_alphord_nums(c("abc9def55", "abc10def7"))
str_alphord_nums(c("01abc9def55", "5abc10def777", "99abc4def4"))
str_alphord_nums(1:10)
# }
# NOT RUN {
str_alphord_nums(c("abc9def55", "abc10xyz7")) # error
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace