diff --git a/DESCRIPTION b/DESCRIPTION index 046e44a..ff6d7e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: backports Type: Package Title: Reimplementations of Functions Introduced Since R-3.0.0 -Version: 1.5.0 +Version: 1.5.0.9000 Authors@R: c( person("Michel", "Lang", NULL, "michellang@gmail.com", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")), diff --git a/NEWS.md b/NEWS.md index de1bd9e..bfbc38b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# backports (development version) + +* Added backport for the `grepv()` function from base for R versions prior to 4.5.0 + # backports 1.5.0 * Added backport for the null-coalesce operator `%||%` for R versions prior to 4.4.0. diff --git a/R/grepv.R b/R/grepv.R new file mode 100644 index 0000000..5c239c8 --- /dev/null +++ b/R/grepv.R @@ -0,0 +1,36 @@ +#' @title Backport of grepv for R < 4.5.0 +#' @rdname grepv +#' +#' @description +#' See the original description in [grepv()]. +#' +#' @keywords internal +#' @rawNamespace if (getRversion() < "4.5.0") export(grepv) +#' @examples +#' # get function from namespace instead of possibly getting +#' # implementation shipped with recent R versions: +#' bp_hasName = getFromNamespace("grepv", "backports") +#' +#' grepv("[a-m]", letters) +grepv = function( + pattern, + x, + ignore.case = FALSE, + perl = FALSE, + value = TRUE, + fixed = FALSE, + useBytes = FALSE, + invert = FALSE +) { + grep( + pattern = pattern, + x = x, + ignore.case = ignore.case, + perl = perl, + value = value, + fixed = fixed, + useBytes = useBytes, + invert = invert + ) +} + diff --git a/README.md b/README.md index a7ee2c6..0ff3a23 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ Note that the braces `{}` are necessary in the `NAMESPACE` file, even though they wouldn't be for regular R code, and that you might get a warning for including `backports` in the `Imports:` section of your `DESCRIPTION` file if you never end up using it. +## Backports for R versions prior to 4.5.0 + +* `base::grepv()` ## Backports for R versions prior to 3.2.0 diff --git a/tests/test-grepv.R b/tests/test-grepv.R new file mode 100644 index 0000000..4fd75f5 --- /dev/null +++ b/tests/test-grepv.R @@ -0,0 +1,10 @@ +source("helper/helper.R") + +if (exists("grepv", envir = baseenv())) { + f = get("grepv", envir = baseenv()) + expect_same = makeCompareFun(f, backports:::grepv) + + expect_same("[a-m]", letters) + expect_same("^\\w{2}", colnames(mtcars)) +} +