String parsing functionalites for generating plotnames, filenames and path. Used by most of my other packages, including CodeAndRoll2 and ggExpress. Many functionalities were part of the formerly used CodeAndRoll (v1).
Install directly from GitHub via devtools with one R command:
# install.packages("devtools"); # If you don't have it.
require("devtools")
devtools::install_github(repo = "vertesy/Stringendo", ref = "main")...then simply load the package:
require("Stringendo")Alternatively, you simply source it from the web. This way function help will not work, and you will have no local copy of the code on your hard drive.
source("https://raw.githubusercontent.com/vertesy/Stringendo/main/R/Stringendo.R")If you encounter a bug, something doesn't work or unclear, please let me know by raising an issue on Stringendo – Please check if it has been asked.
Updated: 2025/12/03 10:53
Stop execution if condition is TRUE. The stopif() function stops the execution if the condition is TRUE. It is the opposite of stopifnot(), which stops if the condition is not TRUE. This function is useful to increase clarity in the code by removing double negations.
Issue warnings if conditions are not TRUE. The warnifnot() function checks whether each condition passed to it is TRUE. If any condition is not met, a warning is issued but execution continues. This is similar to stopifnot(), which throws an error and halts execution, but warnifnot() only issues a warning, allowing the program to proceed.
Issue a warning if condition is TRUE. The warnif() function issues a warning if the condition is TRUE. It is the opposite of warnifnot(), which warns if the condition is not TRUE. This function is useful for issuing warnings when a certain condition is met.
Check whether a variable exists and is TRUE. Returns TRUE if varname exists in the current environment and evaluates to TRUE. If the variable is missing or not TRUE, the function returns FALSE and prints a message describing the problem.
Return a variable's value or a default if it does not exist. Returns the value of varname when it exists; otherwise returns alternative. When v is TRUE, a message is printed indicating whether the variable was found.
Check if Input is Character or NULL. is.character.or.NULL() verifies if the provided input is either a character vector or NULL.
Check if Input is Numeric or Logical. is.numeric.or.logical() checks if the provided input is either numeric or logical.
Test if a Variable is Inherently Numeric ('0.1' as numeric). This function checks if a given variable is inherently numeric. It returns TRUE if the variable can be converted to a numeric value without loss of information and is not inherently a character string, otherwise it returns FALSE.
Negation of the in (w. grapes) operator. %!in% is used to test if elements of one vector are not present in another vector. It is the negation of the %in% operator. This operator returns TRUE for elements of x that are not in y.
Get Object Name as String. get_object_name() captures the name of an input object and returns it as a string. Replace deparse\s*\(\s*substitute\s*\(([^()]+)\)\s*\) to substitute_deparse($1), then substitute\s*\(([^()]+)\)\s*\) to the same.
Message without collapsing. This function prints a message for each element in a character vector, instead of collapsing them into a single line as done by, message().
imessage. A variant to message() pasting with white space, sibling of iprint().
iprint. A more intelligent printing function that collapses any variable passed to it by white spaces.
Parse current date, dot separated.. Returns the current system date and time formatted as a character string. The default format uses dot separated components, but any format recognised by [base::format] can be supplied.
substrRight. Take the right substring of a string
ReplaceRepeatedDots. ReplaceRepeatedDots collapses multiple consecutive dots (periods) in a string into a single dot.
RemoveFinalDot. RemoveFinalDot removes the final dot from a string
RemoveInitialDot. RemoveInitialDot removes the initial dot from a string.
RemoveTrailingDots. RemoveTrailingDots removes dots at the beginning and end of a string.
ReplaceRepeatedSlashes. ReplaceRepeatedSlashes replaces multiple consecutive slashes with a single slash.
RemoveFinalSlash. RemoveFinalSlash removes the final slash(es) from a string (file path).
ReplaceRepeatedUnderscores. ReplaceRepeatedUnderscores replaces multiple consecutive underscores with a single underscore.
RemoveFinalUnderscores. RemoveFinalUnderscores removes trailing underscore(s) from a string.
RemoveWhitespaces. RemoveWhitespaces removes all whitespace characters from a string or replaces them with a specified value.
ReplaceRepeatedWhitespaces. ReplaceRepeatedWhitespaces collapses multiple consecutive whitespace characters into a single replacement.
ReplaceSpecialCharacters. ReplaceSpecialCharacters replaces special characters '[]$@()' with dots.
AddTrailingDotIfMissing. Adds a trailing dot ('.') to a string if it is missing.
AddTrailingSlashIfMissing. Adds a trailing slash ('/') to a string if it is missing.
Paste by point. Paste by point
Paste by (forward) slash. Paste by (forward) slash
Paste by colon symbol.. Paste by colon symbol. "ppc" reserved for "comma".
Paste by underscore. Paste by underscore
Paste by dash. Paste by dash
Collapse and paste by point. Collapse by period (.)
Collapse and paste by underscore. Collapse by underscore (_)
Collapse and paste by (forward) slash. Collapse by forward slash (/)
Collapse and paste by dash. Collapse by dash (-)
Collapse and paste by white space. Collapse by white space ( )
Collapse and paste by a comma followed by a white space. Collapse by comma and white space (, )
Collapse and paste by pipe (|) and white spaces around it. Collapse by pipe (|) with surrounding spaces
Collapse and paste by newline (\n) preceded by a white space. Collapse by newline (\n) preceded by a white space
Collapse and paste Elements With Names. This function takes a named vector and returns a string where each element is pasted with its name. Elements are separated by a specified string, and name-element pairs are also separated by a specified string. The default named vector is c('a' = 1, 'b' = 2).
Kollapse. Collapses values and strings to one string (without a white space). It also prints the results (good for a quick check)
Simplified Paste by point. Simplified Paste by point
Simplified Paste by fwd slash. Simplified Paste by fwd slash
Simplified Paste by underscore. Simplified Paste by underscore
pad.na. This function fills up a vector to a given length by appending NA-values at the end. If the input vector's length is less than the provided length, the function pads the vector with NA. If the vector's length is already equal to or greater than the given length, no change will be made.
percentile2value. Calculate what is the actual value of the N-th percentile in a distribution or set of numbers. Useful for calculating cutoffs, and displaying them by whist()s "vline" parameter.
parsepvalue. Parse p-value from a number to a string.
percentage_formatter. Parse a string of 0-100% from a number between 0 and 1.
Format numbers for human readability. Convert numeric input to character strings with thousands separators and configurable decimal marks.
Identify the dominant separator in a string. Count dots, underscores, and white spaces in a string to guess the most prevalent separator.
Convert a String to camelCase. This function takes a string as input and converts it to camelCase format. It splits the string into words using dots as separators, capitalizes the first letter of each word (except the first word), and then concatenates them back together.
Convert a String to underscore_separated Format. This function converts a string from camelCase or dot-separated format to an underscore-separated format. It can handle strings that are a combination of camelCase and dot-separated formats. The function replaces dots with underscores and inserts an underscore before any uppercase letter that follows a lowercase letter. It then converts all characters to lowercase.
Convert String to Dot Separated Name. Converts a string from camelCase or underscore_separated format to dot.separated.name format. Inserts dots before each uppercase letter (except if it's the first character) or replaces underscores with dots, and then converts the entire string to lowercase.
Convert CamelCase to Sentence. Takes a camelCase string and converts it to a sentence format: space-separated, with the first letter capitalized and no period at the end.
Fix Special Characters for Bash. This function takes a string representing a path and escapes certain special characters to make it compatible with Bash. Specifically, it escapes spaces, opening parentheses, and closing parentheses by placing a backslash before them.
Parse Full File Path. Constructs a full file path by combining a path, file name, and extension. It applies string clean-up operations to each component and ensures proper formatting.
FixUnderscores. FixUnderscores removes multiple consecutive underscores from a string and optionally trims a trailing underscore.
FixPath. FixPath removes multiple consecutive slashes (e.g. '//') from a string and adds a final '/' if missing from a file path.
FixPlotName. FixPlotName replaces special characters in an input string (dollar-, at-, bracket-signs)
ParseDirPath. ParseDirPath pastes elements by slash, then removes Double Slashes '//' from a string and adds a final '/' if missing from a file path.
PasteDirNameFromFlags. Paste a dot (point) separated string from a list of inputs (that can be empty), and clean up the output string from dot multiplets (e.g: ..).
extPDF. add '.pdf' as extension to a file name
extPNG. add '.png' as extension to a file name
Parse Parameter String with Names. This function parses a named vector and intermingles the names and values into a single string, with specified separators for the odd and even elements.
Convert Named Parameters to Filename. This function takes named parameters and converts them into a filename string with specified separators and collapse characters. It excludes any parameters with NULL values.
param.list.2.fname. Take a list of parameters and parse a string from their names and values.
PasteOutdirFromFlags. Paste OutDir from (1) a path and (2) a from a list of inputs (that can be empty), and clean up the output string from dot and forward slash multiplets (e.g: ..).
flag.name_value. Returns the name and its value, if its not FALSE.
flag.nameiftrue. Returns the name and its value, if its TRUE.
flag.names_list. Returns the name and value of each element in a list of parameters.
flag.names_list.all.new. Returns the name and value of each element in a list of parameters.
param.list.flag. Returns the name and value of each element in a list of parameters.
parFlags. Create a string from the names of the (boolean) parameters (TRUE or FALSE) of true values. Use it for Suffixing plot names with the parameters that were used for that plot.
parFlags2. Create a string from the names of the (boolean) parameters (TRUE or FALSE) of true values. Use it for Suffixing plot names with the parameters that were used for that plot.