Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Type: Package
Title: Safe, Multiple, Simultaneous String Substitution
Version: 2.0.0
Authors@R: c(
person("Mark", "Ewing", email="b.mark@ewingsonline.com", role=c("aut","cre"))
person("Mark", "Ewing", email="b.mark.ewing@gmail.com", role=c("aut","cre"))
)
BugReports: https://github.com/bmewing/mgsub/issues
Description: Designed to enable simultaneous substitution in strings in a safe fashion.
Safe means it does not rely on placeholders (which can cause errors in same length matches).
License: MIT + file LICENSE
Encoding: UTF-8
ByteCompile: true
RoxygenNote: 7.3.3
Suggests: testthat,
knitr,
rmarkdown
VignetteBuilder: knitr
URL: https://github.com/bmewing/mgsub, https://bmewing.github.io/mgsub/
Config/roxygen2/version: 8.0.0
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Rewrote key functions in C to provide significant performance boost (4-5x speedup in certain tests)
* `get_matches` and `filter_overlap` are the primary performance enhancers
* `get_matches_base` and `filter_overlap_base` retain the original base R functionality in case of issues with building the code
* Changed maintainer email address because current one was bouncing CRAN emails

# mgsub 1.7.3
* Vignettes were using the qdap package which was not available causing errors. This update only modifies the vignette to remove the use of qdap (and microbenchmark) and so these were removed from the 'suggests'.
Expand All @@ -17,7 +18,7 @@
# mgsub 1.7

* Added the mgsub_censor function which enables fast, simultaneous censoring of patterns
* Trimmed unncessary logic and helper functions
* Trimmed unnecessary logic and helper functions

# mgsub 1.6

Expand Down
4 changes: 4 additions & 0 deletions R/helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ collect_matches = function(string, pattern, ...) {
if (length(pattern) == 0) {
return(collect_matches_base(string, pattern, ...))
}

if (any(is.numeric(pattern))) {
pattern[is.numeric(pattern)] = as.character(pattern[is.numeric(pattern)])
}

if (has_collect_matches_native()) {
return(.Call("_mgsub_collect_matches_cpp", string, pattern, list(...),
Expand Down
2 changes: 2 additions & 0 deletions R/mgsub.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mgsub = function(string, pattern, replacement, recycle=FALSE, ...) {

if (all(is.na(string))) return(string)
sna = !is.na(string)
sn = is.numeric(string)
if (!is.logical(recycle)) stop("Recycle must be a boolean")
if (!recycle & length(pattern) != length(replacement)) {
stop("pattern and replacement vectors must be the same length")
Expand All @@ -40,6 +41,7 @@ mgsub = function(string, pattern, replacement, recycle=FALSE, ...) {
lr = length(replacement)
replacement = rep(replacement, ceiling(lp / lr))[seq_along(pattern)]
}

result = vapply(X = string[sna],
FUN = worker,
FUN.VALUE = c(""),
Expand Down
14 changes: 10 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## Test environments
* local Windows install, R 4.5.0
* Windows Server 2025 (via Github Actions), R 4.5.3
* MacOS 15.7.4 (via Github Actions), R 4.5.3
* local Windows install, R 4.6.0
* Windows Server 2025 (via Github Actions), R 4.6.0
* MacOS 15.7.4 (via Github Actions), R 4.6.0
* ubuntu 24.04.4 LTS (via Github Actions), R 4.6.0
* ubuntu 24.04.4 LTS (via Github Actions), R 4.5.3
* ubuntu 24.04.4 LTS (via Github Actions), R 4.4.3
* ubuntu 24.04.4 LTS (via Github Actions), R-devel

## R CMD check results
There were no ERRORs or WARNINGs.

## Updating maintainer email (this is the NOTE in my check)
I was informed by a maintainer of a downstream package that mgsub
was set to be delisted because CRAN emails were bouncing. I have
been having sporadic issues with my ewingsonline.com domain and
so switched to `b.mark.ewing@gmail.com` in order to address this.
8 changes: 7 additions & 1 deletion man/mgsub-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/get_matches.o
Binary file not shown.
Binary file modified src/mgsub.dll
Binary file not shown.
Binary file modified src/resolve_matches.o
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/testthat/test_mgsub.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ test_that("NAs are correctly handled", {
expect_equal(mgsub(c("string", NA, "test"), c("t"), c("p")), c("spring", NA, "pesp"))
})

test_that("numeric input is handled gracefully", {
expect_equal(mgsub("I live in the 37664 zip code but I'm moving to 99516",
pattern = 37664, replacement=37660),
"I live in the 37660 zip code but I'm moving to 99516")
expect_equal(mgsub("I live in the 37664 zip code but I'm moving to 99516",
pattern = c(37664, "99516"), replacement=c("37660", 58126)),
"I live in the 37660 zip code but I'm moving to 58126")
expect_equal(mgsub(123414, 4, "a"), "123a1a")
})

test_that("recylce has to be a boolean", {
expect_error(mgsub("hey, ho", c("hey"), c("ho", "hey"), recycle = "yes"))
expect_error(mgsub("hey, ho", c("hey"), c("ho", "hey"), recycle = 1))
Expand Down
Loading