Skip to content

Commit

Permalink
Add a function for taking a character vector and returning the line o…
Browse files Browse the repository at this point in the history
…f code used to generate it. Also preparing to use getopt
  • Loading branch information
Nick-Eagles committed Oct 17, 2023
1 parent 43e337e commit deae1fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ get_list_indexing <- function(this_list, index) {
return(list("divisor" = divisor, "modulus" = modulus))
}

# Given a character vector, return an equal-length character vector of
# Given a character vector 'loops', 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)
short_flags = substr(loops, 1, 1)

# Get unused letters
remaining_letters = setdiff(letters, short_flags)
Expand All @@ -29,3 +29,9 @@ get_short_flags = function(loops) {

return(short_flags)
}

# Given a character vector 'vec', return a character(1) representing the line
# of code used to generate 'vec'
vector_as_code = function(vec) {
return(sprintf('c("%s")', paste(vec, collapse = '", "')))
}

0 comments on commit deae1fe

Please sign in to comment.