From eb7bf9b97736c3832ac614b2550f75d2bfb5a859 Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 11 Aug 2025 20:34:48 +0200 Subject: [PATCH 01/24] fix #28 --- CITATION.cff | 2 +- DESCRIPTION | 6 ++---- Development/Create_the_Stringendo_Package.R | 2 ++ Development/config.R | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index d6a1a85..0d41981 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,6 +1,6 @@ cff-version: 1.2.0 title: vertesy/Stringendo -version: v0.8.5 +version: v0.8.6 message: >- If you use this software, please cite it using these metadata. type: software diff --git a/DESCRIPTION b/DESCRIPTION index 201f8e7..67f0967 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,8 @@ Package: Stringendo Title: Stringendo - string parser -Version: 0.8.5 +Version: 0.8.6 Authors@R: person("Abel", "Vertesy", , "av@imba.oeaw.ac.at", role = c("aut", "cre")) -Author: Abel Vertesy [aut, cre] -Maintainer: Abel Vertesy [cre] Description: Stringendo is a set of R functions to parse strings from variables and to manipulate strings. License: GPL-3 + file LICENSE @@ -20,6 +18,6 @@ Suggests: devtools, testthat Encoding: UTF-8 -Packaged: 2025-08-05 15:28:06.697097 +Packaged: 2025-08-11 20:34:02.526465 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 diff --git a/Development/Create_the_Stringendo_Package.R b/Development/Create_the_Stringendo_Package.R index 9738d9f..eb86996 100644 --- a/Development/Create_the_Stringendo_Package.R +++ b/Development/Create_the_Stringendo_Package.R @@ -21,10 +21,12 @@ source(config.path) # install.packages('ggExtra') require(PackageTools) + PackageTools::document_and_create_package(repository.dir, config_file = 'config.R') 'git add commit push to remote' + # Install your package ------------------------------------------------ "disable rprofile by" rprofile() diff --git a/Development/config.R b/Development/config.R index 46aeb71..e00a77f 100644 --- a/Development/config.R +++ b/Development/config.R @@ -3,7 +3,7 @@ DESCRIPTION <- list( package.name = "Stringendo", - version = "0.8.5", + version = "0.8.6", title = "Stringendo - string parser", description = "Stringendo is a set of R functions to parse strings from variables and to manipulate strings.", From e0fa9c49c990dc4317febf894e52e353e03c3563 Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Tue, 12 Aug 2025 13:13:24 +0200 Subject: [PATCH 02/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8647f2..37da47e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Install directly from **GitHub** via **devtools** with one R command: ```R # install.packages("devtools"); # If you don't have it. require("devtools") -devtools::install_github(repo = "vertesy/Stringendo") +devtools::install_github(repo = "vertesy/Stringendo", ref = "main") ``` ...then simply load the package: From 442da8d0c38206369d9ebc807c69eb2aa4c5e324 Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Tue, 12 Aug 2025 15:59:17 +0200 Subject: [PATCH 03/24] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0556a4c..8c2ca40 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ vignettes/*.pdf *.Rproj Stringendo.Rproj Stringendo.Rproj +.DS_Store From 875db438299709cf05177e6da146a5fbd7e43adb Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Tue, 12 Aug 2025 21:27:43 +0200 Subject: [PATCH 04/24] Use requireNamespace in toCamelCase (#31) --- R/Stringendo.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 7ee71da..f9f4ed9 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -1036,7 +1036,7 @@ toCamelCase <- function(input_string, words[-1] <- sapply(words[-1], function(word) { paste0(toupper(substr(word, 1, 1)), tolower(substr(word, 2, nchar(word)))) }) - if (toclipboard & require(clipr)) try(clipr::write_clip(words), silent = TRUE) + if (toclipboard && requireNamespace("clipr", quietly = TRUE)) try(clipr::write_clip(words), silent = TRUE) # Concatenate the words back together return(paste0(words, collapse = "")) From 2b47dc0e7933cbf2103f530d2cfb7847f7781468 Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Tue, 12 Aug 2025 21:31:04 +0200 Subject: [PATCH 05/24] Document and export format_number_h (#30) * Document and export format_number_h * ... --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/Stringendo.R | 23 +++++++++++++---- man/format_number_h.Rd | 29 ++++++++++++++++++++++ tests/testthat/test-format_number_h.R | 9 +++++++ tests/testthat/test-percentage_formatter.R | 4 +-- 6 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 man/format_number_h.Rd create mode 100644 tests/testthat/test-format_number_h.R diff --git a/DESCRIPTION b/DESCRIPTION index 67f0967..5cf9b54 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,4 +20,4 @@ Suggests: Encoding: UTF-8 Packaged: 2025-08-11 20:34:02.526465 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index a693389..c32b9e9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ export(flag.name_value) export(flag.nameiftrue) export(flag.names_list) export(flag.names_list.all.new) +export(format_number_h) export(idate) export(ifExistsAndTrue) export(ifExistsElse) diff --git a/R/Stringendo.R b/R/Stringendo.R index f9f4ed9..27a12c9 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -937,8 +937,22 @@ percentage_formatter <- function(x, digitz = 3, keep.names = FALSE, prefix = NUL return(a) } - -# Format numbers as human readable strings +#' @title Format numbers for human readability +#' +#' @description Convert numeric input to character strings with +#' thousands separators and configurable decimal marks. +#' +#' @param x Numeric vector to format. +#' @param digits Minimum number of significant digits to display. Passed to +#' [format()]. +#' @param big.mark Character used between groups of thousands. +#' @param decimal.mark Character used for the decimal point. +#' +#' @return A character vector containing the formatted numbers. +#' @examples +#' format_number_h(1234) +#' format_number_h(1234.56, digits = 6, decimal.mark = ",") +#' @export format_number_h <- function(x, digits = 1, big.mark = " ", decimal.mark = ".") { stopifnot(is.numeric(x)) x <- format(x, big.mark = big.mark, decimal.mark = decimal.mark, digits = digits) @@ -949,9 +963,8 @@ format_number_h <- function(x, digits = 1, big.mark = " ", decimal.mark = ".") { # _________________________________________________________________________________________________ #' @title Identify the dominant separator in a string #' -#' @description -#' Count dots, underscores, and white spaces in a string to guess the most -#' prevalent separator. +#' @description Count dots, underscores, and white spaces in a string +#' to guess the most prevalent separator. #' #' @param string A character string to analyze. #' @return A character string identifying the dominant separator: "dot", diff --git a/man/format_number_h.Rd b/man/format_number_h.Rd new file mode 100644 index 0000000..6f03b74 --- /dev/null +++ b/man/format_number_h.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Stringendo.R +\name{format_number_h} +\alias{format_number_h} +\title{Format numbers for human readability} +\usage{ +format_number_h(x, digits = 1, big.mark = " ", decimal.mark = ".") +} +\arguments{ +\item{x}{Numeric vector to format.} + +\item{digits}{Minimum number of significant digits to display. Passed to +\code{\link[=format]{format()}}.} + +\item{big.mark}{Character used between groups of thousands.} + +\item{decimal.mark}{Character used for the decimal point.} +} +\value{ +A character vector containing the formatted numbers. +} +\description{ +Convert numeric input to character strings with thousands separators and +configurable decimal marks. +} +\examples{ +format_number_h(1234) +format_number_h(1234.56, digits = 6, decimal.mark = ",") +} diff --git a/tests/testthat/test-format_number_h.R b/tests/testthat/test-format_number_h.R new file mode 100644 index 0000000..ed87394 --- /dev/null +++ b/tests/testthat/test-format_number_h.R @@ -0,0 +1,9 @@ +test_that("format_number_h formats numbers with separators", { + expect_equal(format_number_h(1234), "1 234") + expect_equal(format_number_h(1234.56, digits = 6, decimal.mark = ","), "1 234,56") +}) + +test_that("format_number_h errors on non-numeric input", { + expect_error(format_number_h("a")) +}) + diff --git a/tests/testthat/test-percentage_formatter.R b/tests/testthat/test-percentage_formatter.R index 02cfe47..07a320b 100644 --- a/tests/testthat/test-percentage_formatter.R +++ b/tests/testthat/test-percentage_formatter.R @@ -3,8 +3,8 @@ test_that("standard numeric input yields a formatted percentage", { }) test_that("NA and NaN inputs return NA and NaN strings respectively", { - expect_identical(percentage_formatter(NA), NA) - expect_identical(percentage_formatter(NaN), NaN) + expect_identical(percentage_formatter(NA), NA_character_) + expect_identical(percentage_formatter(NaN), "NaN") }) test_that("named vectors retain names when keep.names = TRUE", { From 6526820b5cf3388e09c7095740b0ab5b74a2697d Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Thu, 14 Aug 2025 12:36:01 +0200 Subject: [PATCH 06/24] Document and export format_number_h (#29) --- R/Stringendo.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/Stringendo.R b/R/Stringendo.R index 27a12c9..91293b7 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -937,6 +937,8 @@ percentage_formatter <- function(x, digitz = 3, keep.names = FALSE, prefix = NUL return(a) } + +# _________________________________________________________________________________________________ #' @title Format numbers for human readability #' #' @description Convert numeric input to character strings with From 2d3ac2de51eb2cf6a360dabe2f4cd689c9851e2c Mon Sep 17 00:00:00 2001 From: vertesy Date: Tue, 19 Aug 2025 15:39:54 +0200 Subject: [PATCH 07/24] rename fun ppnl and kpnl for new line paste/kollapse --- NAMESPACE | 4 ++-- R/Stringendo.R | 14 +++++++------- man/countDotOrUnderscoreSeparated.Rd | 4 ++-- man/format_number_h.Rd | 4 ++-- man/{knl.Rd => kpnl.Rd} | 8 ++++---- man/{pnl.Rd => ppnl.Rd} | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) rename man/{knl.Rd => kpnl.Rd} (85%) rename man/{pnl.Rd => ppnl.Rd} (86%) diff --git a/NAMESPACE b/NAMESPACE index c32b9e9..6ef736e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,9 +40,9 @@ export(imessage) export(iprint) export(is.character.or.NULL) export(is.numeric.or.logical) -export(knl) export(kollapse) export(kpipe) +export(kpnl) export(kpp) export(kppc) export(kppd) @@ -60,10 +60,10 @@ export(parseParamStringWNames) export(parsepvalue) export(percentage_formatter) export(percentile2value) -export(pnl) export(ppcol) export(ppd) export(ppipe) +export(ppnl) export(ppp) export(pps) export(ppu) diff --git a/R/Stringendo.R b/R/Stringendo.R index 91293b7..d86cd16 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -316,7 +316,7 @@ message2 <- function(vec) for (item in vec) message(item) #' @description A variant to message() pasting with white space, sibling of iprint(). #' @param ... Values to collapse consecutively with spaces. #' @param collapse Separator to be used for collapsing. Default: " " -#' +#' #' @examples iprint("Hello ", "you ", 3, ", ", 11, " year old kids.") #' @export @@ -345,7 +345,7 @@ iprint <- function(...) { #' 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. -#' +#' #' @param Format Date format. Default: c("%Y.%m.%d_%H.%M", "%Y.%m.%d_%Hh")[2] #' #' @return A character string of the current date/time formatted according @@ -644,7 +644,7 @@ ppipe <- function(...) { #' #' @param ... Multiple simple variables to parse. #' @export -pnl <- function(...) { +ppnl <- function(...) { paste(..., sep = " \n") } @@ -729,9 +729,9 @@ kpipe <- function(...) { #' @title Collapse and paste by newline (`\n`) preceded by a white space #' @description Collapse by newline (`\n`) preceded by a white space #' @param ... Multiple simple variables to parse. -#' @examples knl("A", 1:2, "end") +#' @examples kpnl("A", 1:2, "end") #' @export -knl <- function(...) { +kpnl <- function(...) { paste(c(...), sep = " \n", collapse = " \n") } @@ -941,7 +941,7 @@ percentage_formatter <- function(x, digitz = 3, keep.names = FALSE, prefix = NUL # _________________________________________________________________________________________________ #' @title Format numbers for human readability #' -#' @description Convert numeric input to character strings with +#' @description Convert numeric input to character strings with #' thousands separators and configurable decimal marks. #' #' @param x Numeric vector to format. @@ -965,7 +965,7 @@ format_number_h <- function(x, digits = 1, big.mark = " ", decimal.mark = ".") { # _________________________________________________________________________________________________ #' @title Identify the dominant separator in a string #' -#' @description Count dots, underscores, and white spaces in a string +#' @description Count dots, underscores, and white spaces in a string #' to guess the most prevalent separator. #' #' @param string A character string to analyze. diff --git a/man/countDotOrUnderscoreSeparated.Rd b/man/countDotOrUnderscoreSeparated.Rd index 946ce38..f7de0ab 100644 --- a/man/countDotOrUnderscoreSeparated.Rd +++ b/man/countDotOrUnderscoreSeparated.Rd @@ -14,8 +14,8 @@ A character string identifying the dominant separator: "dot", "underscore", "white space", "none", or "undecided". } \description{ -Count dots, underscores, and white spaces in a string to guess the most -prevalent separator. +Count dots, underscores, and white spaces in a string +to guess the most prevalent separator. } \examples{ \dontrun{ diff --git a/man/format_number_h.Rd b/man/format_number_h.Rd index 6f03b74..08430b8 100644 --- a/man/format_number_h.Rd +++ b/man/format_number_h.Rd @@ -20,8 +20,8 @@ format_number_h(x, digits = 1, big.mark = " ", decimal.mark = ".") A character vector containing the formatted numbers. } \description{ -Convert numeric input to character strings with thousands separators and -configurable decimal marks. +Convert numeric input to character strings with +thousands separators and configurable decimal marks. } \examples{ format_number_h(1234) diff --git a/man/knl.Rd b/man/kpnl.Rd similarity index 85% rename from man/knl.Rd rename to man/kpnl.Rd index ab7b4c2..7ea0fa6 100644 --- a/man/knl.Rd +++ b/man/kpnl.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/Stringendo.R -\name{knl} -\alias{knl} +\name{kpnl} +\alias{kpnl} \title{Collapse and paste by newline (\verb{\\n}) preceded by a white space} \usage{ -knl(...) +kpnl(...) } \arguments{ \item{...}{Multiple simple variables to parse.} @@ -13,5 +13,5 @@ knl(...) Collapse by newline (\verb{\\n}) preceded by a white space } \examples{ -knl("A", 1:2, "end") +kpnl("A", 1:2, "end") } diff --git a/man/pnl.Rd b/man/ppnl.Rd similarity index 86% rename from man/pnl.Rd rename to man/ppnl.Rd index a493b49..6dc968d 100644 --- a/man/pnl.Rd +++ b/man/ppnl.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/Stringendo.R -\name{pnl} -\alias{pnl} +\name{ppnl} +\alias{ppnl} \title{Paste by new line} \usage{ -pnl(...) +ppnl(...) } \arguments{ \item{...}{Multiple simple variables to parse.} From 4a368e8424b455e943e20f627e8e5ecab48bd949 Mon Sep 17 00:00:00 2001 From: vertesy Date: Tue, 16 Sep 2025 15:24:26 +0200 Subject: [PATCH 08/24] fun ppc Paste by a comma followed by a white space --- NAMESPACE | 1 + R/Stringendo.R | 10 +++++++++- man/kppc.Rd | 2 +- man/ppc.Rd | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 man/ppc.Rd diff --git a/NAMESPACE b/NAMESPACE index 6ef736e..f3c9f6a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -60,6 +60,7 @@ export(parseParamStringWNames) export(parsepvalue) export(percentage_formatter) export(percentile2value) +export(ppc) export(ppcol) export(ppd) export(ppipe) diff --git a/R/Stringendo.R b/R/Stringendo.R index d86cd16..a26e516 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -628,6 +628,14 @@ ppd <- function(...) { paste(..., sep = "-") } +# _________________________________________________________________________________________________ +#' @title Paste by a comma followed by a white space +#' +#' @param ... Multiple simple variables to parse. +#' @export +ppc <- function(...) { + paste(..., sep = ", ") +} # _________________________________________________________________________________________________ #' @title Paste by pipe (|) and white space around it @@ -706,7 +714,7 @@ kppws <- function(...) { # _________________________________________________________________________________________________ -#' @title Collapse and paste by comma (and white space) +#' @title Collapse and paste by a comma followed by a white space #' @description Collapse by comma and white space (`, `) #' @param ... Multiple simple variables to parse. #' @examples kppc("A", 1:2, "end") diff --git a/man/kppc.Rd b/man/kppc.Rd index 3a852a4..3459f2a 100644 --- a/man/kppc.Rd +++ b/man/kppc.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/Stringendo.R \name{kppc} \alias{kppc} -\title{Collapse and paste by comma (and white space)} +\title{Collapse and paste by a comma followed by a white space} \usage{ kppc(...) } diff --git a/man/ppc.Rd b/man/ppc.Rd new file mode 100644 index 0000000..4cbeb30 --- /dev/null +++ b/man/ppc.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Stringendo.R +\name{ppc} +\alias{ppc} +\title{Paste by a comma followed by a white space} +\usage{ +ppc(...) +} +\arguments{ +\item{...}{Multiple simple variables to parse.} +} +\description{ +Paste by a comma followed by a white space +} From 9303bd947fd2616ab2830d7a431b8e6f0e7d8cde Mon Sep 17 00:00:00 2001 From: Abel Vertesy Date: Mon, 20 Oct 2025 19:08:35 +0200 Subject: [PATCH 09/24] Fix unsafe and inconsistent string utilities (#32) (#33) * Fix unsafe and inconsistent string utilities * No need for sep NA handling * regex clarified --- R/Stringendo.R | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index a26e516..2368c49 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -185,7 +185,7 @@ ifExistsAndTrue <- function(varname = "pi" ) { #' @examples ifExistsElse("pi"); ifExistsElse("pi22") #' #' @export -ifExistsElse <- function(varname, alternative = "define an alternative", v = F ) { +ifExistsElse <- function(varname, alternative = "define an alternative", v = FALSE ) { if(!is.character(varname)) varname <- deparse(substitute(varname)) if(v) message("Checking if ", varname, " exists.") if(exists(varname)) get(varname) else alternative @@ -249,13 +249,13 @@ is.numeric.or.logical <- function(x) { #' testNumericCompatible("0.1") # Should return TRUE #' testNumericCompatible("apple") # Should return FALSE #' testNumericCompatible("arma.0.1") # Should return FALSE -testNumericCompatible <- function(x) { - stopifnot(is.numeric(x) || is.character(x)) - suppressWarnings({ - x_is_numeric <- !is.na(as.numeric(x)) & is.numeric(as.numeric(x)) - }) - return(x_is_numeric) -} + testNumericCompatible <- function(x) { + stopifnot(is.numeric(x) || is.character(x)) + suppressWarnings({ + x_is_numeric <- !is.na(as.numeric(x)) + }) + return(x_is_numeric) + } # _____________________________________________________________________________________________________________________________ @@ -535,7 +535,17 @@ ReplaceRepeatedWhitespaces <- function(string, replacement = " ") { #' @export ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement = ".", remove_dots = FALSE) { - x <- gsub(x = string, pattern = ",|\\||\\@|\\[|\\]|\\$|\\/\\(\\)|\\\\", replacement = replacement) + # , comma + # @ at sign + # \| pipe + # \[ left bracket + # \] right bracket + # \$ dollar sign + # \( left parenthesis + # \) right parenthesis + # \\ backslash + # / forward slash + x <- gsub(x = string, pattern = "[,@\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) x <- ReplaceRepeatedWhitespaces(x) if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") ReplaceRepeatedDots(x) @@ -572,7 +582,7 @@ AddTrailingDotIfMissing <- function(string = "stairway.to.heaven") { #' @export AddTrailingSlashIfMissing <- function(string = "stairway/to/heaven") { LastChr <- substr(string, nchar(string), nchar(string)) - if (!LastChr == "/") { + if (LastChr != "/") { string <- paste0(string, "/") } return(string) @@ -761,7 +771,7 @@ kpnl <- function(...) { #' @export kpwNames <- function(x = c("a" = 1, "b" = 2), sep1 = ": ", sep2 = " | ", prefix = NULL, suffix = NULL) { - if(is.table(x) & length(dim(x))) { + if (is.table(x) && length(dim(x)) > 0) { # Convert one dimensional table to vector preserving the names nmz <- names(x) x <- as.vector(x) @@ -1006,10 +1016,10 @@ countDotOrUnderscoreSeparated <- function(string) { estimated_separator <- dplyr::case_when( dot_count > max(usc_count, ws_count) ~ "dot", - usc_count > max(usc_count, ws_count) ~ "underscore", + usc_count > max(dot_count, ws_count) ~ "underscore", ws_count > max(dot_count, usc_count) ~ "white space", - dot_count == 0 & usc_count == 0 & ws_count == 0 ~ "none", - dot_count == usc_count & dot_count == usc_count ~ "undecided" + dot_count == 0 && usc_count == 0 && ws_count == 0 ~ "none", + dot_count == usc_count && dot_count == ws_count ~ "undecided" ) message("Estimated separator: ", estimated_separator) @@ -1141,7 +1151,7 @@ toDotSeparated <- function(input_string, toclipboard = TRUE) { stopifnot(is.character(result), nchar(result) > 0) # Handle clipboard functionality - if (toclipboard & requireNamespace("clipr", quietly = TRUE)) try(clipr::write_clip(result), silent = TRUE) + if (toclipboard && requireNamespace("clipr", quietly = TRUE)) try(clipr::write_clip(result), silent = TRUE) message(result) } @@ -1277,7 +1287,7 @@ FixPath <- function(string = "stairway//to/heaven", ..., is.file = FALSE) { string <- ReplaceRepeatedDots(string) string <- ReplaceRepeatedSlashes(string) LastChr <- substr(string, nchar(string), nchar(string)) - if (!is.file & !LastChr == "/") { + if (!is.file && LastChr != "/") { string <- paste0(string, "/") } return(string) From dd2c462955fee2232233db0b25fb5d0df4b9c997 Mon Sep 17 00:00:00 2001 From: vertesy Date: Thu, 23 Oct 2025 22:24:44 +0200 Subject: [PATCH 10/24] ... --- man/ifExistsElse.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/ifExistsElse.Rd b/man/ifExistsElse.Rd index f6c5d92..c0131f8 100644 --- a/man/ifExistsElse.Rd +++ b/man/ifExistsElse.Rd @@ -4,7 +4,7 @@ \alias{ifExistsElse} \title{Return a variable's value or a default if it does not exist} \usage{ -ifExistsElse(varname, alternative = "define an alternative", v = F) +ifExistsElse(varname, alternative = "define an alternative", v = FALSE) } \arguments{ \item{varname}{Character string naming the variable to retrieve.} From 4973e89fa7bfa4170b6bd93963a513df36586de3 Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 3 Dec 2025 10:45:37 +0100 Subject: [PATCH 11/24] ... --- .../Create_the_Stringendo_Package.OLD.R | 141 ------------------ 1 file changed, 141 deletions(-) delete mode 100644 Development/Create_the_Stringendo_Package.OLD.R diff --git a/Development/Create_the_Stringendo_Package.OLD.R b/Development/Create_the_Stringendo_Package.OLD.R deleted file mode 100644 index 4dc6621..0000000 --- a/Development/Create_the_Stringendo_Package.OLD.R +++ /dev/null @@ -1,141 +0,0 @@ -###################################################################################################### -# Create_the_Stringendo_Package.R -###################################################################################################### -# source("~/GitHub/Packages/Stringendo/Development/Create_the_Stringendo_Package.R") -rm(list = ls(all.names = TRUE)); -try(dev.off(), silent = TRUE) - - -# Functions ------------------------ -# require("devtools") -# require("roxygen2") -# require("stringr") - -# # devtools::install_github(repo = "vertesy/CodeAndRoll2") -# require('CodeAndRoll2') -# # try (source('~/GitHub/Packages/CodeAndRoll/CodeAndRoll.R'),silent= FALSE) # ONLY If Stringendo not yet exist -# require('Stringendo') - -# Setup ------------------------ -package.name <- "Stringendo" -package.version <- "0.5.0" -setwd("~/GitHub/Packages/") - -RepositoryDir <- paste0("~/GitHub/Packages/", package.name, "/") -fname <- paste0(package.name, ".R") -Package_FnP <- paste0(RepositoryDir, "R/", fname) - -BackupDir <- "~/GitHub/Packages/Stringendo/Development/" -dir.create(BackupDir) - -# devtools::use_package("vioplot") -DESCRIPTION <- list("Title" = "Stringendo - string parser" - , "Author" = person(given = "Abel", family = "Vertesy", email = "abel.vertesy@imba.oeaw.ac.at", role = c("aut", "cre") ) - , "Authors@R" = 'person(given = "Abel", family = "Vertesy", email = "a.vertesy@imba.oeaw.ac.at", role = c("aut", "cre") )' - , "Description" = "Stringendo is a set of R functions to parse strings from variables and to manipulate strings." - , "License" = "GPL-3 + file LICENSE" - , "Version" = package.version - , "Packaged" = Sys.time() - # , "Repository" = "CRAN" - # , "Depends" = "" - # , "Imports" = "devtools, grDevices, usethis, MarkdownReports" - , "Imports" = "clipr" - , "Suggests" = "MarkdownHelpers, MarkdownReports" - , "BugReports"= "https://github.com/vertesy/Stringendo/issues" -) - - -setwd(RepositoryDir) -if ( !dir.exists(RepositoryDir) ) { create(path = RepositoryDir, description = DESCRIPTION, rstudio = TRUE) -} else { - getwd() - try(file.remove(c("DESCRIPTION","NAMESPACE", "Stringendo.Rproj"))) - usethis::create_package(path = RepositoryDir, fields = DESCRIPTION, open = F) -} - - -# go and write fun's ------------------------------------------------------------------------ -# file.edit(Package_FnP) - -# Create Roxygen Skeletons ------------------------ -# RoxygenReady(Package_FnP) - -# replace output files ------------------------------------------------ -BackupOldFile <- (paste0(BackupDir, "Development", ".bac")) -AnnotatedFile <- (paste0(BackupDir, "Development", ".annot.R")) -file.copy(from = Package_FnP, to = BackupOldFile, overwrite = TRUE) -# file.copy(from = AnnotatedFile, to = Package_FnP, overwrite = TRUE) - -# Manual editing of descriptors ------------------------------------------------ -# file.edit(Package_FnP) - -# Compile a package ------------------------------------------------ -setwd(RepositoryDir) -getwd() -devtools::document() -warnings() - - -{ - "update cff version" - citpath <- paste0(RepositoryDir, 'CITATION.cff') - xfun::gsub_file(file = citpath, perl = T - , "^version: v.+", paste0("version: v", package.version)) -} - - -# Install your package ------------------------------------------------ -# # setwd(RepositoryDir) -# unload("Stringendo") -devtools::install(RepositoryDir, upgrade = F) - -'after uploading' -pak::pkg_install('vertesy/Stringendo') - -# require("Stringendo") -# # remove.packages("Stringendo") -# # Test your package ------------------------------------------------ -# help("wplot") -# cat("\014") -# devtools::run_examples() - - -# Test if you can install from github ------------------------------------------------ -# devtools::install_github(repo = "vertesy/Stringendo") - -# require("Stringendo") - -# Clean up if not needed anymore ------------------------------------------------ -# View(installed.packages()) -# remove.packages("Stringendo") - -check(RepositoryDir, cran = TRUE) -# as.package(RepositoryDir) -# -# -# # source("https://install-github.me/r-lib/desc") -# # library(desc) -# # desc$set("Stringendo", "foo") -# # desc$get(Stringendo) -# -# -# system("cd ~/GitHub/Stringendo/; ls -a; open .Rbuildignore") - -# Check package dependencies ------------------------------------------------ -depFile = paste0(RepositoryDir, 'Development/Dependencies.R') - -(f.deps <- NCmisc::list.functions.in.file(filename = Package_FnP)) -# clipr::write_clip(f.deps) - -sink(file = depFile); print(f.deps); sink() -p.deps <- gsub(x = names(f.deps), pattern = 'package:', replacement = '') -write(x = p.deps, file = depFile, append = T) -p.dep.declared <- trimws(unlist(strsplit(DESCRIPTION$Imports, ","))) -p.dep.new <- sort(union( p.deps, p.dep.declared)) -# clipr::write_clip(p.dep.new) - - -# Linter and Styler ------------------------------------------------ - - -styler::style_file("~/GitHub/Packages/Stringendo/R/Stringendo.R") From 518fdf64e9553657778af23e38f7321ce8e5b427 Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 3 Dec 2025 10:51:59 +0100 Subject: [PATCH 12/24] yearly docs update --- CITATION.cff | 2 +- DESCRIPTION | 8 +- Development/Create_the_Stringendo_Package.R | 5 +- Development/config.R | 4 +- R/Stringendo.R | 63 ++++--- README.md | 196 +++++++++++--------- man/ifExistsElse.Rd | 3 +- man/is.character.or.NULL.Rd | 4 +- man/is.numeric.or.logical.Rd | 6 +- man/substitute_deparse.Rd | 2 +- tests/testthat/test-format_number_h.R | 1 - 11 files changed, 162 insertions(+), 132 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 0d41981..f4d2006 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,6 +1,6 @@ cff-version: 1.2.0 title: vertesy/Stringendo -version: v0.8.6 +version: v1.1.1 message: >- If you use this software, please cite it using these metadata. type: software diff --git a/DESCRIPTION b/DESCRIPTION index 5cf9b54..647e479 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Stringendo -Title: Stringendo - string parser -Version: 0.8.6 +Title: Stringendo - string manipulation utilities +Version: 1.1.1 Authors@R: person("Abel", "Vertesy", , "av@imba.oeaw.ac.at", role = c("aut", "cre")) Description: Stringendo is a set of R functions to parse strings from @@ -18,6 +18,6 @@ Suggests: devtools, testthat Encoding: UTF-8 -Packaged: 2025-08-11 20:34:02.526465 +Packaged: 2025-12-03 10:48:04.078783 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.1 diff --git a/Development/Create_the_Stringendo_Package.R b/Development/Create_the_Stringendo_Package.R index eb86996..12e8d48 100644 --- a/Development/Create_the_Stringendo_Package.R +++ b/Development/Create_the_Stringendo_Package.R @@ -84,8 +84,8 @@ if (F) { for (scriptX in ls.scripts.full.path) { PackageTools::list_of_funs_to_markdown(scriptX) } -file.edit(paste0(repository.dir, "R/list.of.functions.in.", package.name, ".det.md")) -file.edit(paste0(repository.dir, "README.md")) +file.edit(paste0(repository.dir, "/R/list.of.functions.in.", package.name, ".det.md")) +file.edit(paste0(repository.dir, "/README.md")) file.remove(paste0(repository.dir, "/R/list.of.functions.in.", package.name, ".det.md")) r$PackageTools() @@ -101,6 +101,7 @@ for (scriptX in ls.scripts.full.path) { } +PackageTools::document_and_create_package(repository.dir, config_file = 'config.R') diff --git a/Development/config.R b/Development/config.R index e00a77f..ee233b3 100644 --- a/Development/config.R +++ b/Development/config.R @@ -3,8 +3,8 @@ DESCRIPTION <- list( package.name = "Stringendo", - version = "0.8.6", - title = "Stringendo - string parser", + version = "1.1.1", + title = "Stringendo - string manipulation utilities", description = "Stringendo is a set of R functions to parse strings from variables and to manipulate strings.", depends = "base", diff --git a/R/Stringendo.R b/R/Stringendo.R index 2368c49..debdd2b 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -38,7 +38,7 @@ #' #' @export stopif <- function(...) { - args <- list(...) # Capture all conditions + args <- list(...) # Capture all conditions for (i in seq_along(args)) { condition <- args[[i]] @@ -57,7 +57,7 @@ stopif <- function(...) { } } - invisible() # No visible output + invisible() # No visible output } @@ -83,7 +83,7 @@ stopif <- function(...) { #' #' @export warnifnot <- function(...) { - args <- list(...) # Capture all conditions + args <- list(...) # Capture all conditions for (i in seq_along(args)) { condition <- args[[i]] @@ -102,7 +102,7 @@ warnifnot <- function(...) { } } - invisible() # No visible output + invisible() # No visible output } @@ -126,7 +126,7 @@ warnifnot <- function(...) { #' #' @export warnif <- function(...) { - args <- list(...) # Capture all conditions + args <- list(...) # Capture all conditions for (i in seq_along(args)) { condition <- args[[i]] @@ -145,7 +145,7 @@ warnif <- function(...) { } } - invisible() # No visible output + invisible() # No visible output } @@ -164,10 +164,15 @@ warnif <- function(...) { #' #' @export -ifExistsAndTrue <- function(varname = "pi" ) { - x = FALSE +ifExistsAndTrue <- function(varname = "pi") { + x <- FALSE if (exists(varname)) { - if (isTRUE(get(varname))) {x = TRUE} else {x = FALSE; iprint(varname, " exists, but != TRUE; ", get(varname))} + if (isTRUE(get(varname))) { + x <- TRUE + } else { + x <- FALSE + iprint(varname, " exists, but != TRUE; ", get(varname)) + } } return(x) } @@ -182,13 +187,14 @@ ifExistsAndTrue <- function(varname = "pi" ) { #' @param alternative Value to return if `varname` is not defined. #' @param v Logical indicating whether to print informative messages. Default is `FALSE`. #' -#' @examples ifExistsElse("pi"); ifExistsElse("pi22") +#' @examples ifExistsElse("pi") +#' ifExistsElse("pi22") #' #' @export -ifExistsElse <- function(varname, alternative = "define an alternative", v = FALSE ) { - if(!is.character(varname)) varname <- deparse(substitute(varname)) - if(v) message("Checking if ", varname, " exists.") - if(exists(varname)) get(varname) else alternative +ifExistsElse <- function(varname, alternative = "define an alternative", v = FALSE) { + if (!is.character(varname)) varname <- deparse(substitute(varname)) + if (v) message("Checking if ", varname, " exists.") + if (exists(varname)) get(varname) else alternative } @@ -202,9 +208,9 @@ ifExistsElse <- function(varname, alternative = "define an alternative", v = FAL #' @return Returns `TRUE` if `x` is either a character vector or `NULL`, otherwise `FALSE`. #' #' @examples -#' is.character.or.NULL(NULL) # TRUE +#' is.character.or.NULL(NULL) # TRUE #' is.character.or.NULL("example") # TRUE -#' is.character.or.NULL(123) # FALSE +#' is.character.or.NULL(123) # FALSE #' #' @export is.character.or.NULL <- function(x) is.null(x) || is.character(x) @@ -221,9 +227,9 @@ is.character.or.NULL <- function(x) is.null(x) || is.character(x) #' @return Returns `TRUE` if `x` is either numeric or logical, otherwise `FALSE`. #' #' @examples -#' is.numeric.or.logical(123) # TRUE -#' is.numeric.or.logical(TRUE) # TRUE -#' is.numeric.or.logical("text") # FALSE +#' is.numeric.or.logical(123) # TRUE +#' is.numeric.or.logical(TRUE) # TRUE +#' is.numeric.or.logical("text") # FALSE #' #' @export is.numeric.or.logical is.numeric.or.logical <- function(x) { @@ -249,13 +255,13 @@ is.numeric.or.logical <- function(x) { #' testNumericCompatible("0.1") # Should return TRUE #' testNumericCompatible("apple") # Should return FALSE #' testNumericCompatible("arma.0.1") # Should return FALSE - testNumericCompatible <- function(x) { - stopifnot(is.numeric(x) || is.character(x)) - suppressWarnings({ - x_is_numeric <- !is.na(as.numeric(x)) - }) - return(x_is_numeric) - } +testNumericCompatible <- function(x) { + stopifnot(is.numeric(x) || is.character(x)) + suppressWarnings({ + x_is_numeric <- !is.na(as.numeric(x)) + }) + return(x_is_numeric) +} # _____________________________________________________________________________________________________________________________ @@ -294,7 +300,7 @@ is.numeric.or.logical <- function(x) { #' #' @examples #' my_var <- 10 -#' get_object_name(my_var) # "my_var" +#' get_object_name(my_var) # "my_var" #' #' @export substitute_deparse <- function(x) deparse(substitute(x)) @@ -770,7 +776,6 @@ kpnl <- function(...) { #' @examples kpwNames(c("a" = 1, "b" = 2)) #' @export kpwNames <- function(x = c("a" = 1, "b" = 2), sep1 = ": ", sep2 = " | ", prefix = NULL, suffix = NULL) { - if (is.table(x) && length(dim(x)) > 0) { # Convert one dimensional table to vector preserving the names nmz <- names(x) @@ -810,7 +815,7 @@ kollapse <- function(..., if (print == 1) { print(paste0(c(...), collapse = collapseby)) } else if (print == 2) { - message(paste0(c(...), collapse = collapseby)) + message(paste0(c(...), collapse = collapseby)) } paste0(c(...), collapse = collapseby) } diff --git a/README.md b/README.md index 37da47e..b6bea81 100644 --- a/README.md +++ b/README.md @@ -38,210 +38,234 @@ source("https://raw.githubusercontent.com/vertesy/Stringendo/main/R/Stringendo.R
-## List of Functions in Stringendo.R (67) -Updated: 2024/10/24 11:02 +## List of Functions in Stringendo.R (76) +Updated: 2025/12/03 10:48 - #### 1 `stopif()` 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. - #### 2 `warnifnot()` -Issue warnings if conditions are not TRUE. The `warningifnot()` function checks whether each condition passed to it is `TRUE`. If any condition is not met, a warning is issued but the execution continues. This is similar to `stopifnot()`, which throws an error and halts execution, but `warningifnot()` only issues a warning, allowing the program to proceed. +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. - #### 3 `warnif()` -Issue a warning if condition is TRUE. The `warnif()` function issues a warning if the condition is `TRUE`. It is the opposite of `warningifnot()`, which warns if the condition is not `TRUE`. This function is useful for issuing warnings when a certain condition is met. +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. -- #### 4 `testNumericCompatible()` +- #### 4 `ifExistsAndTrue()` +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. + +- #### 5 `ifExistsElse()` +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. + +- #### 6 `is.character.or.NULL()` +Check if Input is Character or NULL. `is.character.or.NULL()` verifies if the provided input is either a character vector or NULL. + +- #### 7 `is.numeric.or.logical()` +Check if Input is Numeric or Logical. `is.numeric.or.logical()` checks if the provided input is either numeric or logical. + +- #### 8 `testNumericCompatible()` 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. -- #### 5 `"%!in%"()` +- #### 9 `"%!in%"()` 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`. -- #### 6 `message2()` +- #### 10 `substitute_deparse()` +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. + +- #### 11 `message2()` 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()`. -- #### 7 `imessage()` +- #### 12 `imessage()` imessage. A variant to message() pasting with white space, sibling of iprint(). -- #### 8 `HasNames()` +- #### 13 `iprint()` iprint. A more intelligent printing function that collapses any variable passed to it by white spaces. -- #### 9 `substrRight()` +- #### 14 `HasNames()` +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. + +- #### 15 `substrRight()` substrRight. Take the right substring of a string -- #### 10 `ReplaceRepeatedDots()` -ReplaceRepeatedDots. ReplaceRepeatedDots removes multiple consecutive slashes (e.g. '..') from a string (file path). +- #### 16 `ReplaceRepeatedDots()` +ReplaceRepeatedDots. ReplaceRepeatedDots collapses multiple consecutive dots (periods) in a string into a single dot. -- #### 11 `RemoveFinalDot()` +- #### 17 `RemoveFinalDot()` RemoveFinalDot. RemoveFinalDot removes the final dot from a string -- #### 12 `RemoveInitialDot()` +- #### 18 `RemoveInitialDot()` RemoveInitialDot. RemoveInitialDot removes the initial dot from a string. -- #### 13 `RemoveTrailingDots()` +- #### 19 `RemoveTrailingDots()` RemoveTrailingDots. RemoveTrailingDots removes dots at the beginning and end of a string. -- #### 14 `ReplaceRepeatedSlashes()` +- #### 20 `ReplaceRepeatedSlashes()` ReplaceRepeatedSlashes. ReplaceRepeatedSlashes replaces multiple consecutive slashes with a single slash. -- #### 15 `RemoveFinalSlash()` +- #### 21 `RemoveFinalSlash()` RemoveFinalSlash. RemoveFinalSlash removes the final slash(es) from a string (file path). -- #### 16 `ReplaceRepeatedUnderscores()` -ReplaceRepeatedUnderscores. ReplaceRepeatedUnderscores replaces multiple consecutive slashes with a single slash. +- #### 22 `ReplaceRepeatedUnderscores()` +ReplaceRepeatedUnderscores. ReplaceRepeatedUnderscores replaces multiple consecutive underscores with a single underscore. -- #### 17 `RemoveFinalUnderscores()` -RemoveFinalUnderscores. RemoveFinalUnderscores removes the final slash(es) from a string (file path). +- #### 23 `RemoveFinalUnderscores()` +RemoveFinalUnderscores. RemoveFinalUnderscores removes trailing underscore(s) from a string. -- #### 18 `RemoveWhitespaces()` -RemoveWhitespaces. RemoveWhitespaces replaces any nr of white spaces. +- #### 24 `RemoveWhitespaces()` +RemoveWhitespaces. RemoveWhitespaces removes all whitespace characters from a string or replaces them with a specified value. -- #### 19 `ReplaceRepeatedWhitespaces()` -ReplaceRepeatedWhitespaces. ReplaceRepeatedWhitespaces replaces multiple consecutive white spaces with a single one. +- #### 25 `ReplaceRepeatedWhitespaces()` +ReplaceRepeatedWhitespaces. ReplaceRepeatedWhitespaces collapses multiple consecutive whitespace characters into a single replacement. -- #### 20 `ReplaceSpecialCharacters()` +- #### 26 `ReplaceSpecialCharacters()` ReplaceSpecialCharacters. ReplaceSpecialCharacters replaces special characters '[]$@()' with dots. -- #### 21 `AddTrailingDotIfMissing()` +- #### 27 `AddTrailingDotIfMissing()` AddTrailingDotIfMissing. Adds a trailing dot ('.') to a string if it is missing. -- #### 22 `AddTrailingSlashIfMissing()` +- #### 28 `AddTrailingSlashIfMissing()` AddTrailingSlashIfMissing. Adds a trailing slash ('/') to a string if it is missing. -- #### 23 `ppp()` +- #### 29 `ppp()` Paste by point. Paste by point -- #### 24 `pps()` +- #### 30 `pps()` Paste by (forward) slash. Paste by (forward) slash -- #### 25 `ppu()` +- #### 31 `ppcol()` +Paste by colon symbol.. Paste by colon symbol. "ppc" reserved for "comma". + +- #### 32 `ppu()` Paste by underscore. Paste by underscore -- #### 26 `pnl()` +- #### 33 `ppnl()` Paste by dash. Paste by dash -- #### 27 `kpp()` -Collapse and paste by point. Collapse by point +- #### 34 `kpp()` +Collapse and paste by point. Collapse by period (`.`) -- #### 28 `kppu()` -Collapse and paste by underscore. Collapse by underscore +- #### 35 `kppu()` +Collapse and paste by underscore. Collapse by underscore (`_`) -- #### 29 `kpps()` -Collapse and paste by (forward) slash. Collapse by (forward) slash +- #### 36 `kpps()` +Collapse and paste by (forward) slash. Collapse by forward slash (`/`) -- #### 30 `kppd()` -Collapse and paste by dash. Collapse by dash +- #### 37 `kppd()` +Collapse and paste by dash. Collapse by dash (`-`) -- #### 31 `kppws()` -Collapse and paste by white space. Collapse by white space +- #### 38 `kppws()` +Collapse and paste by white space. Collapse by white space (` `) -- #### 32 `kppc()` -Collapse and paste by comma (and white space). Collapse by white space +- #### 39 `kppc()` +Collapse and paste by a comma followed by a white space. Collapse by comma and white space (`, `) -- #### 33 `kpipe()` -Collapse and paste by pipe (|) and white spaces around it. Collapse by white space +- #### 40 `kpipe()` +Collapse and paste by pipe (|) and white spaces around it. Collapse by pipe (`|`) with surrounding spaces -- #### 34 `knl()` -Collapse and paste by newline (`\n`) preceded by a white space. Collapse by white space +- #### 41 `kpnl()` +Collapse and paste by newline (`\n`) preceded by a white space. Collapse by newline (`\n`) preceded by a white space -- #### 35 `kpwNames()` +- #### 42 `kpwNames()` 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)`. -- #### 36 `kollapse()` +- #### 43 `kollapse()` Kollapse. Collapses values and strings to one string (without a white space). It also prints the results (good for a quick check) -- #### 37 `sppp()` +- #### 44 `sppp()` Simplified Paste by point. Simplified Paste by point -- #### 38 `spps()` +- #### 45 `spps()` Simplified Paste by fwd slash. Simplified Paste by fwd slash -- #### 39 `sppu()` +- #### 46 `sppu()` Simplified Paste by underscore. Simplified Paste by underscore -- #### 40 `percentile2value()` +- #### 47 `pad.na()` +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. + +- #### 48 `percentile2value()` 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. -- #### 41 `parsepvalue()` +- #### 49 `parsepvalue()` parsepvalue. Parse p-value from a number to a string. -- #### 42 `format_number_h()` +- #### 50 `percentage_formatter()` percentage_formatter. Parse a string of 0-100% from a number between 0 and 1. -- #### 43 `countDotOrUnderscoreSeparated()` -Count Dots or Underscores in a String and return. This function counts the number of "." characters in a given string. +- #### 51 `format_number_h()` +Format numbers for human readability. Convert numeric input to character strings with thousands separators and configurable decimal marks. + +- #### 52 `countDotOrUnderscoreSeparated()` +Identify the dominant separator in a string. Count dots, underscores, and white spaces in a string to guess the most prevalent separator. -- #### 44 `toCamelCase()` +- #### 53 `toCamelCase()` 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. -- #### 45 `toUnderscoreSeparated()` +- #### 54 `toUnderscoreSeparated()` 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. -- #### 46 `toDotSeparated()` +- #### 55 `toDotSeparated()` 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. -- #### 47 `toSentence()` +- #### 56 `toSentence()` 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. -- #### 48 `fix_special_characters_bash()` +- #### 57 `fix_special_characters_bash()` 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. -- #### 49 `ParseFullFilePath()` +- #### 58 `ParseFullFilePath()` 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. -- #### 50 `FixUnderscores()` -FixUnderscores. FixUnderscores removes multiple consecutive underscores (e.g. '_') from a string, and optionally also removes a final '_'. +- #### 59 `FixUnderscores()` +FixUnderscores. FixUnderscores removes multiple consecutive underscores from a string and optionally trims a trailing underscore. -- #### 51 `FixPath()` +- #### 60 `FixPath()` FixPath. FixPath removes multiple consecutive slashes (e.g. '//') from a string and adds a final '/' if missing from a file path. -- #### 52 `FixPlotName()` +- #### 61 `FixPlotName()` FixPlotName. FixPlotName replaces special characters in an input string (dollar-, at-, bracket-signs) -- #### 53 `ParseDirPath()` +- #### 62 `ParseDirPath()` ParseDirPath. ParseDirPath pastes elements by slash, then removes Double Slashes '//' from a string and adds a final '/' if missing from a file path. -- #### 54 `PasteDirNameFromFlags()` +- #### 63 `PasteDirNameFromFlags()` 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: ..). -- #### 55 `extPDF()` +- #### 64 `extPDF()` extPDF. add '.pdf' as extension to a file name -- #### 56 `extPNG()` +- #### 65 `extPNG()` extPNG. add '.png' as extension to a file name -- #### 57 `parseParamStringWNames()` +- #### 66 `parseParamStringWNames()` 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. -- #### 58 `params.2.fname()` +- #### 67 `params.2.fname()` 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. -- #### 59 `param.list.2.fname()` +- #### 68 `param.list.2.fname()` param.list.2.fname. Take a list of parameters and parse a string from their names and values. -- #### 60 `PasteOutdirFromFlags()` +- #### 69 `PasteOutdirFromFlags()` 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: ..). -- #### 61 `flag.name_value()` +- #### 70 `flag.name_value()` flag.name_value. Returns the name and its value, if its not FALSE. -- #### 62 `flag.nameiftrue()` +- #### 71 `flag.nameiftrue()` flag.nameiftrue. Returns the name and its value, if its TRUE. -- #### 63 `flag.names_list()` +- #### 72 `flag.names_list()` flag.names_list. Returns the name and value of each element in a list of parameters. -- #### 64 `flag.names_list.all.new()` +- #### 73 `flag.names_list.all.new()` flag.names_list.all.new. Returns the name and value of each element in a list of parameters. -- #### 65 `param.list.flag()` +- #### 74 `param.list.flag()` param.list.flag. Returns the name and value of each element in a list of parameters. -- #### 66 `()` +- #### 75 `()` 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. -- #### 67 `FormatAsExcelLink()` +- #### 76 `FormatAsExcelLink()` 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. - - - diff --git a/man/ifExistsElse.Rd b/man/ifExistsElse.Rd index c0131f8..f10d23c 100644 --- a/man/ifExistsElse.Rd +++ b/man/ifExistsElse.Rd @@ -18,6 +18,7 @@ Returns the value of \code{varname} when it exists; otherwise returns \code{alte When \code{v} is \code{TRUE}, a message is printed indicating whether the variable was found. } \examples{ -ifExistsElse("pi"); ifExistsElse("pi22") +ifExistsElse("pi") +ifExistsElse("pi22") } diff --git a/man/is.character.or.NULL.Rd b/man/is.character.or.NULL.Rd index 9754862..2d2be40 100644 --- a/man/is.character.or.NULL.Rd +++ b/man/is.character.or.NULL.Rd @@ -16,8 +16,8 @@ Returns \code{TRUE} if \code{x} is either a character vector or \code{NULL}, oth \code{is.character.or.NULL()} verifies if the provided input is either a character vector or NULL. } \examples{ -is.character.or.NULL(NULL) # TRUE +is.character.or.NULL(NULL) # TRUE is.character.or.NULL("example") # TRUE -is.character.or.NULL(123) # FALSE +is.character.or.NULL(123) # FALSE } diff --git a/man/is.numeric.or.logical.Rd b/man/is.numeric.or.logical.Rd index fd6138f..156f091 100644 --- a/man/is.numeric.or.logical.Rd +++ b/man/is.numeric.or.logical.Rd @@ -16,8 +16,8 @@ Returns \code{TRUE} if \code{x} is either numeric or logical, otherwise \code{FA \code{is.numeric.or.logical()} checks if the provided input is either numeric or logical. } \examples{ -is.numeric.or.logical(123) # TRUE -is.numeric.or.logical(TRUE) # TRUE -is.numeric.or.logical("text") # FALSE +is.numeric.or.logical(123) # TRUE +is.numeric.or.logical(TRUE) # TRUE +is.numeric.or.logical("text") # FALSE } diff --git a/man/substitute_deparse.Rd b/man/substitute_deparse.Rd index 025b4b1..05ea701 100644 --- a/man/substitute_deparse.Rd +++ b/man/substitute_deparse.Rd @@ -19,6 +19,6 @@ Replace \verb{deparse\\s*\\(\\s*substitute\\s*\\(([^()]+)\\)\\s*\\)} to \verb{su } \examples{ my_var <- 10 -get_object_name(my_var) # "my_var" +get_object_name(my_var) # "my_var" } diff --git a/tests/testthat/test-format_number_h.R b/tests/testthat/test-format_number_h.R index ed87394..23114ad 100644 --- a/tests/testthat/test-format_number_h.R +++ b/tests/testthat/test-format_number_h.R @@ -6,4 +6,3 @@ test_that("format_number_h formats numbers with separators", { test_that("format_number_h errors on non-numeric input", { expect_error(format_number_h("a")) }) - From c1cb31a97d0d069b074425a362f935a4b66c76ea Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 3 Dec 2025 10:56:51 +0100 Subject: [PATCH 13/24] ... --- DESCRIPTION | 2 +- R/Stringendo.R | 9 +++------ README.md | 5 ++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 647e479..7510b18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,6 @@ Suggests: devtools, testthat Encoding: UTF-8 -Packaged: 2025-12-03 10:48:04.078783 +Packaged: 2025-12-03 10:56:21.465331 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 diff --git a/R/Stringendo.R b/R/Stringendo.R index debdd2b..99848ff 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -1563,15 +1563,13 @@ param.list.flag <- function(par = p$"umap.min_dist") { #' MyPlotname #' #' @export -parFlags <- - function(prefix = "", +parFlags <- function(prefix = "", ..., pasteflg = TRUE, collapsechar = ".") { namez <- as.character(as.list(match.call())[-(1:2)]) val <- c(...) names(val) <- namez - # flg = names(which(as.logical.wNames(val))) # which_names() flg <- names(val)[val] print(flg) flg <- if (pasteflg) { @@ -1598,8 +1596,7 @@ parFlags <- #' MyPlotname #' #' @export -parFlags2 <- - function(prefix = ".", +parFlags2 <- function(prefix = ".", ..., pasteflg = TRUE, coll.char = ".", @@ -1627,7 +1624,7 @@ parFlags2 <- #' @param max.char Max characters per line #' @examples ww.break.lines(char.vec = kppd(LETTERS)) #' -#' @export +#' @export ww.break.lines ww.break.lines <- function(char.vec, max.char = 50) { gsub(pattern = paste0("(.{", max.char, "})"), "\\1\n", char.vec) } diff --git a/README.md b/README.md index b6bea81..0ec8d6b 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ source("https://raw.githubusercontent.com/vertesy/Stringendo/main/R/Stringendo.R
## List of Functions in Stringendo.R (76) -Updated: 2025/12/03 10:48 - +Updated: 2025/12/03 10:53 - #### 1 `stopif()` 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. @@ -263,7 +262,7 @@ flag.names_list.all.new. Returns the name and value of each element in a list of - #### 74 `param.list.flag()` param.list.flag. Returns the name and value of each element in a list of parameters. -- #### 75 `()` +- #### 75 `parFlags()` 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. - #### 76 `FormatAsExcelLink()` From f28ec07230d0f7795e74321a345b922837d942bb Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 3 Dec 2025 13:24:37 +0100 Subject: [PATCH 14/24] ... --- CITATION.cff | 2 +- Development/CITATION.cff | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 Development/CITATION.cff diff --git a/CITATION.cff b/CITATION.cff index f4d2006..1f29eee 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -7,6 +7,6 @@ type: software authors: - given-names: Abel family-names: Vertesy - email: abel.vertesy@imba.oeaw.ac.at + email: av@imba.oeaw.ac.at affiliation: IMBA orcid: 'https://orcid.org/0000-0001-6075-5702' diff --git a/Development/CITATION.cff b/Development/CITATION.cff new file mode 100644 index 0000000..e69de29 From 4f3540fdd0899678d1b4f9e1de9db913bad9448c Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 15 Dec 2025 17:08:46 +0100 Subject: [PATCH 15/24] nf warnifnot Better warning message. --- R/Stringendo.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 99848ff..12a9a9a 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -93,10 +93,11 @@ warnifnot <- function(...) { if (!(is.logical(condition) && all(condition, na.rm = TRUE))) { # Use the provided name as a custom warning message if it exists, # otherwise, use the condition's expression + default_msg <- paste(deparse(match.call()[[i + 1]]), "is not TRUE") message <- if (!is.null(name) && nzchar(name)) { - paste(name, "is not TRUE") + paste(name, "\n", default_msg, "\n") } else { - paste(deparse(match.call()[[i + 1]]), "is not TRUE") + default_msg } warning(message, call. = FALSE, immediate. = TRUE) } From 3329824c85a4f09902342af70bcd4632fc0f97e0 Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 15 Dec 2025 17:10:34 +0100 Subject: [PATCH 16/24] nf warnif: Better warning message. --- R/Stringendo.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 12a9a9a..4e5aa12 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -94,6 +94,7 @@ warnifnot <- function(...) { # Use the provided name as a custom warning message if it exists, # otherwise, use the condition's expression default_msg <- paste(deparse(match.call()[[i + 1]]), "is not TRUE") + message <- if (!is.null(name) && nzchar(name)) { paste(name, "\n", default_msg, "\n") } else { @@ -102,8 +103,7 @@ warnifnot <- function(...) { warning(message, call. = FALSE, immediate. = TRUE) } } - - invisible() # No visible output + invisible() } @@ -137,16 +137,17 @@ warnif <- function(...) { if (is.logical(condition) && all(condition, na.rm = TRUE)) { # Use the provided name as a custom warning message if it exists, # otherwise, use the condition's expression + default_msg <- paste(deparse(match.call()[[i + 1]]), "is TRUE") + message <- if (!is.null(name) && nzchar(name)) { - paste(name, "is TRUE") + paste(name, "\n", default_msg, "\n") } else { - paste(deparse(match.call()[[i + 1]]), "is TRUE") + default_msg } warning(message, call. = FALSE, immediate. = TRUE) } } - - invisible() # No visible output + invisible() } From 3ee6b3d0c43fa35295062e63575e5f8c6c95c7fb Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 12 Jan 2026 14:47:59 +0100 Subject: [PATCH 17/24] ud flag.names_list --- NAMESPACE | 1 - R/Stringendo.R | 27 ++++++++++++++------------- man/flag.names_list.Rd | 19 +++++++++++++------ man/flag.names_list.all.new.Rd | 14 -------------- 4 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 man/flag.names_list.all.new.Rd diff --git a/NAMESPACE b/NAMESPACE index f3c9f6a..da5cc90 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,7 +31,6 @@ export(fix_special_characters_bash) export(flag.name_value) export(flag.nameiftrue) export(flag.names_list) -export(flag.names_list.all.new) export(format_number_h) export(idate) export(ifExistsAndTrue) diff --git a/R/Stringendo.R b/R/Stringendo.R index 4e5aa12..c211759 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -1515,28 +1515,28 @@ flag.nameiftrue <- function(toggle, prefix = NULL, suffix = NULL, name.if.not = # _________________________________________________________________________________________________ -#' @title flag.names_list -#' @description Returns the name and value of each element in a list of parameters. -#' @param par A list element e.g.: p$umap -#' @examples # flag.names_list(par = p$'umap.n_neighbors') -#' -#' @export -flag.names_list <- function(par) { - if (length(par)) paste(substitute(par), kppu(par), sep = "_")[[3]] -} +#' #' @title flag.names_list +#' #' @description Returns the name and value of each element in a list of parameters. +#' #' @param par A list element e.g.: p$umap +#' #' @examples # flag.names_list(par = p$'umap.n_neighbors') +#' #' +#' #' @export +#' flag.names_list <- function(par) { +#' if (length(par)) paste(substitute(par), kppu(par), sep = "_")[[3]] +#' } # _________________________________________________________________________________________________ #' @title flag.names_list.all.new #' @description Returns the name and value of each element in a list of parameters. -#' @param pl List of parameters, Default: p.hm +#' @param ls List of parameters (name, value), Default: p.hm #' #' @export -flag.names_list.all.new <- function(pl = p.hm) { - # if (length(pl)) paste(kppu(names(pl)), kppu(pl) , sep = "_") - if (length(pl)) kppd(paste(names(pl), pl, sep = "_")) +flag.names_list <- function(ls = p.hm, sep = "_") { + if (length(ls)) kppd(paste(names(ls), ls, sep = sep)) } +flag.names_list.all.new <- function() .Deprecated("flag.names_list") # _________________________________________________________________________________________________ #' @title param.list.flag @@ -1569,6 +1569,7 @@ parFlags <- function(prefix = "", ..., pasteflg = TRUE, collapsechar = ".") { + .deprecated("parFlags2") namez <- as.character(as.list(match.call())[-(1:2)]) val <- c(...) names(val) <- namez diff --git a/man/flag.names_list.Rd b/man/flag.names_list.Rd index 677df49..bd3c217 100644 --- a/man/flag.names_list.Rd +++ b/man/flag.names_list.Rd @@ -2,17 +2,24 @@ % Please edit documentation in R/Stringendo.R \name{flag.names_list} \alias{flag.names_list} -\title{flag.names_list} +\title{flag.names_list.all.new} \usage{ -flag.names_list(par) +flag.names_list(ls = p.hm, sep = "_") } \arguments{ -\item{par}{A list element e.g.: p$umap} +\item{ls}{List of parameters (name, value), Default: p.hm} } \description{ Returns the name and value of each element in a list of parameters. } -\examples{ -# flag.names_list(par = p$'umap.n_neighbors') - +\details{ +#' @title flag.names_list +#' @description Returns the name and value of each element in a list of parameters. +#' @param par A list element e.g.: p$umap +#' @examples # flag.names_list(par = p$'umap.n_neighbors') +#' +#' @export +flag.names_list <- function(par) { +if (length(par)) paste(substitute(par), kppu(par), sep = "_")[\link{3}] +} } diff --git a/man/flag.names_list.all.new.Rd b/man/flag.names_list.all.new.Rd deleted file mode 100644 index 8c03bc1..0000000 --- a/man/flag.names_list.all.new.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Stringendo.R -\name{flag.names_list.all.new} -\alias{flag.names_list.all.new} -\title{flag.names_list.all.new} -\usage{ -flag.names_list.all.new(pl = p.hm) -} -\arguments{ -\item{pl}{List of parameters, Default: p.hm} -} -\description{ -Returns the name and value of each element in a list of parameters. -} From a92ce6ed810032f16ff1d9d3860f58333340f15b Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 12 Jan 2026 14:56:01 +0100 Subject: [PATCH 18/24] ud flag.names_list --- R/Stringendo.R | 12 ++++++++---- man/flag.names_list.Rd | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index c211759..37c961a 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -1530,11 +1530,17 @@ flag.nameiftrue <- function(toggle, prefix = NULL, suffix = NULL, name.if.not = #' @title flag.names_list.all.new #' @description Returns the name and value of each element in a list of parameters. #' @param ls List of parameters (name, value), Default: p.hm +#' @param sep_name_val Separator name-2-value, Default: "_" +#' @param sep_elem Separator between elements, Default: "-" #' #' @export -flag.names_list <- function(ls = p.hm, sep = "_") { - if (length(ls)) kppd(paste(names(ls), ls, sep = sep)) +flag.names_list <- function(ls = p.hm, sep_name_val = "_", sep_elem = "-") { + if (length(ls)) + paste(paste(names(ls), ls, sep = sep_name_val), collapse = sep_elem) } +# flag.names_list <- function(ls = p.hm, sep_elem = "_") { +# if (length(ls)) kppd(paste(names(ls), ls, sep = sep_elem)) +# } flag.names_list.all.new <- function() .Deprecated("flag.names_list") @@ -1619,7 +1625,6 @@ parFlags2 <- function(prefix = ".", - # _________________________________________________________________________________________________ #' @title break.lines for plot titles #' @@ -1634,7 +1639,6 @@ ww.break.lines <- function(char.vec, max.char = 50) { - # _________________________________________________________________________________________________ #' @title FormatAsExcelLink #' diff --git a/man/flag.names_list.Rd b/man/flag.names_list.Rd index bd3c217..f8ca3ae 100644 --- a/man/flag.names_list.Rd +++ b/man/flag.names_list.Rd @@ -4,10 +4,14 @@ \alias{flag.names_list} \title{flag.names_list.all.new} \usage{ -flag.names_list(ls = p.hm, sep = "_") +flag.names_list(ls = p.hm, sep_name_val = "_", sep_elem = "-") } \arguments{ \item{ls}{List of parameters (name, value), Default: p.hm} + +\item{sep_name_val}{Separator name-2-value, Default: "_"} + +\item{sep_elem}{Separator between elements, Default: "-"} } \description{ Returns the name and value of each element in a list of parameters. From 2858535ae3e301ee0eeffa857639294aa32666ed Mon Sep 17 00:00:00 2001 From: vertesy Date: Mon, 2 Feb 2026 16:45:04 +0100 Subject: [PATCH 19/24] ... --- R/Stringendo.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/Stringendo.R b/R/Stringendo.R index 37c961a..4dd5f7f 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -194,6 +194,7 @@ ifExistsAndTrue <- function(varname = "pi") { #' #' @export ifExistsElse <- function(varname, alternative = "define an alternative", v = FALSE) { + .Deprecated("get0") if (!is.character(varname)) varname <- deparse(substitute(varname)) if (v) message("Checking if ", varname, " exists.") if (exists(varname)) get(varname) else alternative From 1ab12bce9397396dd12c3ce89b0c1610969b27d7 Mon Sep 17 00:00:00 2001 From: vertesy Date: Thu, 12 Mar 2026 00:12:19 +0100 Subject: [PATCH 20/24] bf ReplaceSpecialCharacters now replaces control characters --- R/Stringendo.R | 6 ++++-- man/ReplaceSpecialCharacters.Rd | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 4dd5f7f..ebababd 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -537,13 +537,14 @@ ReplaceRepeatedWhitespaces <- function(string, replacement = " ") { #' #' @description ReplaceSpecialCharacters replaces special characters '[]$@()' with dots. #' @param string The string potentially having special characters. -#' @param replacement The character to replace special characters with. +#' @param replacement The character to replace special characters with. Pattern = `"[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/]"` #' @param remove_dots If TRUE, all dots are removed from the string (overwrites if replacement is a dot). #' @examples ReplaceSpecialCharacters(string = "obj@meta$alpha[[3]]") #' @return A string with special characters replaced by dots. #' @export ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement = ".", remove_dots = FALSE) { + # [:cntrl:] control characters # , comma # @ at sign # \| pipe @@ -554,7 +555,8 @@ ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement # \) right parenthesis # \\ backslash # / forward slash - x <- gsub(x = string, pattern = "[,@\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) + x <- gsub(x = string, pattern = "[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) + # Old one "[,@\\|\\[\\]\\$\\(\\)\\\\/]" x <- ReplaceRepeatedWhitespaces(x) if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") ReplaceRepeatedDots(x) diff --git a/man/ReplaceSpecialCharacters.Rd b/man/ReplaceSpecialCharacters.Rd index ddb3b81..aae45a4 100644 --- a/man/ReplaceSpecialCharacters.Rd +++ b/man/ReplaceSpecialCharacters.Rd @@ -13,7 +13,7 @@ ReplaceSpecialCharacters( \arguments{ \item{string}{The string potentially having special characters.} -\item{replacement}{The character to replace special characters with.} +\item{replacement}{The character to replace special characters with. Pattern = \verb{"[[:cntrl:]@,\\\\|\\\[\\\]\\\\$\\\\(\\\\)\\\\\\\\/]"}} \item{remove_dots}{If TRUE, all dots are removed from the string (overwrites if replacement is a dot).} } From 87834fea865fb9bb80b8d5aa66a4731e3f80d1f2 Mon Sep 17 00:00:00 2001 From: vertesy Date: Fri, 13 Mar 2026 17:10:11 +0100 Subject: [PATCH 21/24] ... --- R/Stringendo.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index ebababd..0d884c5 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -531,7 +531,6 @@ ReplaceRepeatedWhitespaces <- function(string, replacement = " ") { } - # _________________________________________________________________________________________________ #' @title ReplaceSpecialCharacters #' @@ -545,7 +544,7 @@ ReplaceRepeatedWhitespaces <- function(string, replacement = " ") { ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement = ".", remove_dots = FALSE) { # [:cntrl:] control characters - # , comma + # ,:; comma, colon, semicolon # @ at sign # \| pipe # \[ left bracket @@ -555,7 +554,7 @@ ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement # \) right parenthesis # \\ backslash # / forward slash - x <- gsub(x = string, pattern = "[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) + x <- gsub(x = string, pattern = "[[:cntrl:],:;@\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) # Old one "[,@\\|\\[\\]\\$\\(\\)\\\\/]" x <- ReplaceRepeatedWhitespaces(x) if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") From 13ca546f5ac8eb7ed9d7e1032a74952737ef8e81 Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 25 Mar 2026 22:37:02 +0100 Subject: [PATCH 22/24] bf ReplaceSpecialCharacters --- R/Stringendo.R | 24 +++++++++++++++++++----- man/ReplaceSpecialCharacters.Rd | 3 ++- man/parsepvalue.Rd | 6 +++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 0d884c5..7e441c7 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -536,7 +536,8 @@ ReplaceRepeatedWhitespaces <- function(string, replacement = " ") { #' #' @description ReplaceSpecialCharacters replaces special characters '[]$@()' with dots. #' @param string The string potentially having special characters. -#' @param replacement The character to replace special characters with. Pattern = `"[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/]"` +#' @param replacement The character to replace special characters with. +#' Pattern = `"[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/<>\\{\\}]"` #' @param remove_dots If TRUE, all dots are removed from the string (overwrites if replacement is a dot). #' @examples ReplaceSpecialCharacters(string = "obj@meta$alpha[[3]]") #' @return A string with special characters replaced by dots. @@ -549,12 +550,20 @@ ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement # \| pipe # \[ left bracket # \] right bracket + # < left angle brackets + # > right angle brackets + # { left curly brackets + # } right curly brackets + # \$ dollar sign # \( left parenthesis # \) right parenthesis # \\ backslash # / forward slash - x <- gsub(x = string, pattern = "[[:cntrl:],:;@\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) + # Pattern to replace including angle And curvy brackets. + x <- gsub(x = string, pattern = "[[:cntrl:]@,\\|\\[\\]\\$\\(\\)\\\\/<>\\{\\}]", replacement = replacement, perl = TRUE) + # x <- gsub(x = string, pattern = "[[:cntrl:],:;@\\|\\[\\]\\$\\(\\)\\\\/]", replacement = replacement, perl = TRUE) + # Old one "[,@\\|\\[\\]\\$\\(\\)\\\\/]" x <- ReplaceRepeatedWhitespaces(x) if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") @@ -934,10 +943,15 @@ percentile2value <- function(distribution, percentile = 0.95, FirstValOverPercen #' @title parsepvalue #' @description Parse p-value from a number to a string. #' @param pvalue pvalue to parse. Default: 0.01 - +#' @param digits Number of digits to keep. Default: 2 +#' @param brackets Whether to enclose the result in brackets. Default: FALSE #' @export -parsepvalue <- function(pvalue = 0.01) paste0("(p<", pvalue, ")") -# Parse p-value from a number to a string. +parsepvalue <- function(pvalue = 0.01, digits = 2, brackets = F, prefix = F) { + pv <- paste0("p<=", signif(pvalue, digits = digits ), "") + if (brackets) paste0("(", pv, ")") else pv + if (!isFALSE(prefix)) paste0(prefix, pv) else pv +} + # _________________________________________________________________________________________________ diff --git a/man/ReplaceSpecialCharacters.Rd b/man/ReplaceSpecialCharacters.Rd index aae45a4..f7239ce 100644 --- a/man/ReplaceSpecialCharacters.Rd +++ b/man/ReplaceSpecialCharacters.Rd @@ -13,7 +13,8 @@ ReplaceSpecialCharacters( \arguments{ \item{string}{The string potentially having special characters.} -\item{replacement}{The character to replace special characters with. Pattern = \verb{"[[:cntrl:]@,\\\\|\\\[\\\]\\\\$\\\\(\\\\)\\\\\\\\/]"}} +\item{replacement}{The character to replace special characters with. +Pattern = \verb{"[[:cntrl:]@,\\\\|\\\[\\\]\\\\$\\\\(\\\\)\\\\\\\\/<>\\\\\{\\\\\}]"}} \item{remove_dots}{If TRUE, all dots are removed from the string (overwrites if replacement is a dot).} } diff --git a/man/parsepvalue.Rd b/man/parsepvalue.Rd index 9528c0b..8af9268 100644 --- a/man/parsepvalue.Rd +++ b/man/parsepvalue.Rd @@ -4,10 +4,14 @@ \alias{parsepvalue} \title{parsepvalue} \usage{ -parsepvalue(pvalue = 0.01) +parsepvalue(pvalue = 0.01, digits = 2, brackets = F, prefix = F) } \arguments{ \item{pvalue}{pvalue to parse. Default: 0.01} + +\item{digits}{Number of digits to keep. Default: 2} + +\item{brackets}{Whether to enclose the result in brackets. Default: FALSE} } \description{ Parse p-value from a number to a string. From 3d8f5cad4b395af1e2a9ec73766608a8f95c094f Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 25 Mar 2026 22:39:57 +0100 Subject: [PATCH 23/24] bf ReplaceSpecialCharacters --- R/Stringendo.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 7e441c7..4abc491 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -566,8 +566,10 @@ ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement # Old one "[,@\\|\\[\\]\\$\\(\\)\\\\/]" x <- ReplaceRepeatedWhitespaces(x) - if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") + # Replace " ." or ". " with "." + x <- gsub(x = x, pattern = " \\.|\\. ", replacement = ".", perl = TRUE) ReplaceRepeatedDots(x) + if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") else x } From 95b6240b6edc8277c8a31469bc56f3785370f98b Mon Sep 17 00:00:00 2001 From: vertesy Date: Fri, 27 Mar 2026 22:36:37 +0100 Subject: [PATCH 24/24] ... --- R/Stringendo.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/Stringendo.R b/R/Stringendo.R index 4abc491..3847190 100644 --- a/R/Stringendo.R +++ b/R/Stringendo.R @@ -567,7 +567,8 @@ ReplaceSpecialCharacters <- function(string = "obj@meta$alpha[[3]]", replacement # Old one "[,@\\|\\[\\]\\$\\(\\)\\\\/]" x <- ReplaceRepeatedWhitespaces(x) # Replace " ." or ". " with "." - x <- gsub(x = x, pattern = " \\.|\\. ", replacement = ".", perl = TRUE) + x <- gsub(x = x, pattern = " \\.", replacement = ".", perl = TRUE ) + x <- gsub(x = x, pattern = "\\. ", replacement = ".", perl = TRUE ) ReplaceRepeatedDots(x) if (remove_dots) x <- gsub(x = x, pattern = "\\.", replacement = "") else x }