Commit ff41a431 authored by Jonathan Mang's avatar Jonathan Mang 💡
Browse files

refactor: added `tolower` and `toupper` to function `string_replacements`

parent bfd5f7e8
Pipeline #22833 passed with stages
in 34 minutes and 11 seconds
......@@ -6,6 +6,8 @@
#' @param replace_mapping (Optional, list, default = "default") The mapping
#' containing what should be replaced with what:
#' `replace_mapping <- list("replace_this" = "with_this")`
#' @param tolower (boolean, default = FALSE) Should the result be lowercase?
#' @param toupper (boolean, default = FALSE) Should the result be uppercase?
#'
#' @return (String) All elements (names) of the input `replace_mapping` or
#' the default mapping are replaced by its values of the mapping.
......@@ -16,7 +18,7 @@
#'
#' @export
#'
string_replacements <- function(input, replace_mapping = "default") {
string_replacements <- function(input, replace_mapping = "default", tolower = FALSE, toupper = FALSE) {
res <- input
replaceme <- list(
# "replace_this" = "with_this",
......@@ -71,5 +73,12 @@ string_replacements <- function(input, replace_mapping = "default") {
}
iteration <- iteration + 1
}
if (tolower) {
res <- tolower(res)
} else if (toupper) {
res <- toupper(res)
}
return(res)
}
......@@ -4,7 +4,12 @@
\alias{string_replacements}
\title{Clean string with a given set of replacements}
\usage{
string_replacements(input, replace_mapping = "default")
string_replacements(
input,
replace_mapping = "default",
tolower = FALSE,
toupper = FALSE
)
}
\arguments{
\item{input}{(string) The character string to be processed.}
......@@ -12,6 +17,10 @@ string_replacements(input, replace_mapping = "default")
\item{replace_mapping}{(Optional, list, default = "default") The mapping
containing what should be replaced with what:
`replace_mapping <- list("replace_this" = "with_this")`}
\item{tolower}{(boolean, default = FALSE) Should the result be lowercase?}
\item{toupper}{(boolean, default = FALSE) Should the result be uppercase?}
}
\value{
(String) All elements (names) of the input `replace_mapping` or
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment