diff --git a/R/utils.R b/R/utils.R index 9df9d9f..d73f24d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,3 +10,22 @@ get_list_indexing <- function(this_list, index) { return(list("divisor" = divisor, "modulus" = modulus)) } + +# Given a character vector, return an equal-length character vector of +# unique one-letter initials +get_short_flags = function(loops) { + # Try just taking the first letter of the names + short_flags = substr(names(loops), 1, 1) + + # Get unused letters + remaining_letters = setdiff(letters, short_flags) + if (length(remaining_letters) == 0) { + stop("Can't handle more than 26 loops.") + } + + # Overwrite duplicates with unused letters + dup_flags = duplicated(short_flags) + short_flags[dup_flags] = remaining_letters[1:length(which(dup_flags))] + + return(short_flags) +}