Skip to content
Open
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
36 changes: 36 additions & 0 deletions R/grepv.R
Original file line number Diff line number Diff line change
@@ -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
)
}

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions tests/test-grepv.R
Original file line number Diff line number Diff line change
@@ -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))
}

Loading