From 20c285aa041ba9bee860e6db6b8571bd0a5c8065 Mon Sep 17 00:00:00 2001 From: dustinstoltz Date: Fri, 17 Apr 2026 12:11:18 -0400 Subject: [PATCH] Fix dead ignore.case parameter in replace_contraction() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ignore.case parameter was accepted but not used — the function always passed ignore.case=TRUE to mgsub(). Now passes the user-provided value through, making the parameter functional. Backwards compatible: default is still ignore.case=TRUE. --- R/replace_contraction.R | 2 +- tests/testthat/test-replace_contraction.R | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100755 tests/testthat/test-replace_contraction.R diff --git a/R/replace_contraction.R b/R/replace_contraction.R index 93cfca3..156d682 100644 --- a/R/replace_contraction.R +++ b/R/replace_contraction.R @@ -26,7 +26,7 @@ function(x, contraction.key = lexicon::key_contractions, ignore.case=TRUE, ...) { mgsub(x, contraction.key[[1]], contraction.key[[2]], - fixed = FALSE, ignore.case=TRUE) + fixed = FALSE, ignore.case = ignore.case) } diff --git a/tests/testthat/test-replace_contraction.R b/tests/testthat/test-replace_contraction.R new file mode 100755 index 0000000..3513d10 --- /dev/null +++ b/tests/testthat/test-replace_contraction.R @@ -0,0 +1,15 @@ +context("Checking replace_contraction") + +test_that("replace_contraction replaces contractions with ignore.case=TRUE (default)", { + x <- c("Mr. Jones isn't going.", "She's here but didn't go.", "It ISN'T here") + result <- replace_contraction(x) + expect_true(grepl("is not", result[1])) + expect_true(grepl("did not", result[2])) + expect_true(grepl("is not", result[2])) +}) + +test_that("replace_contraction respects ignore.case=FALSE", { + x <- c("ISN'T going", "isn't going") + expect_equal(replace_contraction(x, ignore.case = FALSE)[1], "ISN'T going") + expect_true(grepl("is not", replace_contraction(x, ignore.case = FALSE)[2])) +}) \ No newline at end of file