From deae1fea9ff5c1711bf024cd6ff0f2184367d5c3 Mon Sep 17 00:00:00 2001 From: Nick-Eagles Date: Tue, 17 Oct 2023 14:57:00 -0400 Subject: [PATCH] Add a function for taking a character vector and returning the line of code used to generate it. Also preparing to use getopt --- R/utils.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index d73f24d..3787dc8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) @@ -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 = '", "'))) +}