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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: traumar
Title: Calculate Metrics for Trauma System Performance
Version: 1.2.6.9000
Version: 1.2.7
Authors@R: c(
person("Nicolas", "Foss", , "nicolas.foss@hhs.iowa.gov", role = c("aut", "cre")),
person("Iowa Department of Health and Human Services", role = "cph")
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# traumar (development version)
# traumar 1.2.7
- Deprecated `%not_in%` in favor of the `base` R `%notin%` operator (available
in `R 4.6.0`). Calls to `%not_in%` now produce a deprecation warning, and
users are encouraged to migrate to the `base` operator.

# traumar 1.2.6
- Deprecate the `n_decimal` argument for `pretty_number()`, use `digits`
Expand Down
17 changes: 14 additions & 3 deletions R/not_in.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#' @title Check if Elements Are Not in a Vector
#'
#' @description This function returns a logical vector indicating whether each
#' element of `x` is not in `y`.
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' `%not_in%` has been **deprecated** because base R (>= 4.6.0) now provides the
#' `%notin%` operator.
#'
#' Please use `%notin%` from `base` instead.
#'
#' @param x A vector of values to be checked.
#'
Expand Down Expand Up @@ -31,6 +36,12 @@
#' @export
#'
`%not_in%` <- function(x, y) {
# this function is now deprecated as of 1.2.7
lifecycle::deprecate_warn(
when = "1.2.7",
what = "`%not_in%`()",
with = "base::`%notin%`()",
details = "`base` R includes the %notin% operator as of R >= 4.6.0."
)
!(x %in% y)

}
9 changes: 3 additions & 6 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## R CMD check results

0 errors | 0 warnings | 1 note
0 errors | 0 warnings | 0 notes

* checking for future file timestamps ... NOTE
unable to verify current time
* This is a patch release.
* Breaking changes are expected in `pretty_number()` due to deprecating an
argument.
* This is a patch release. It deprecates the %not_in% function and refers users
to base R's %notin%.
8 changes: 6 additions & 2 deletions man/grapes-not_in-grapes.Rd

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

116 changes: 70 additions & 46 deletions tests/testthat/test-not_in.R
Original file line number Diff line number Diff line change
@@ -1,115 +1,139 @@
test_that("`%not_in%` works with character vectors", {
testthat::test_that("`%not_in%` works with character vectors", {
x <- c("apple", "banana", "cherry")
y <- c("banana", "grape")

result <- x %not_in% y
expected <- c(TRUE, FALSE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, TRUE)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)

#testthat::expect_equal(result, expected)
})

test_that("`%not_in%` works with numeric vectors", {
testthat::test_that("`%not_in%` works with numeric vectors", {
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6)

result <- x %not_in% y
expected <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, TRUE, FALSE, TRUE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with logical vectors", {
testthat::test_that("`%not_in%` works with logical vectors", {
x <- c(TRUE, FALSE, TRUE)
y <- c(FALSE)

result <- x %not_in% y
expected <- c(TRUE, FALSE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, TRUE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with mixed types", {
testthat::test_that("`%not_in%` works with mixed types", {
x <- c(1, "banana", TRUE)
y <- c("banana", 2, FALSE)

result <- x %not_in% y
expected <- c(TRUE, FALSE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, TRUE)

expect_equal(result, expected)
# testthat::expect_equal(result, expected)

testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with empty vectors", {
testthat::test_that("`%not_in%` works with empty vectors", {
x <- character(0)
y <- c("apple", "banana")

result <- x %not_in% y
expected <- logical(0)
# result <- x %not_in% y
# expected <- logical(0)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)

x <- c("apple", "banana")
y <- character(0)

result <- x %not_in% y
expected <- c(TRUE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, TRUE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with NA values in `x` and `y`", {
testthat::test_that("`%not_in%` works with NA values in `x` and `y`", {
x <- c(NA, "apple", NA)
y <- c("banana", NA)

result <- x %not_in% y
expected <- c(FALSE, TRUE, FALSE)
# result <- x %not_in% y
# expected <- c(FALSE, TRUE, FALSE)

expect_equal(result, expected)
# testthat::expect_equal(result, expected)

testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with identical `x` and `y`", {
testthat::test_that("`%not_in%` works with identical `x` and `y`", {
x <- c("apple", "banana", "cherry")
y <- c("apple", "banana", "cherry")

result <- x %not_in% y
expected <- c(FALSE, FALSE, FALSE)
# result <- x %not_in% y
# expected <- c(FALSE, FALSE, FALSE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` handles duplicates in `x` and `y`", {
testthat::test_that("`%not_in%` handles duplicates in `x` and `y`", {
x <- c("apple", "banana", "banana", "cherry")
y <- c("banana", "banana", "grape")

result <- x %not_in% y
expected <- c(TRUE, FALSE, FALSE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, FALSE, TRUE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with NULL values in `x` or `y`", {
testthat::test_that("`%not_in%` works with NULL values in `x` or `y`", {
x <- c("apple", "banana", "cherry")
y <- NULL

result <- x %not_in% y
expected <- c(TRUE, TRUE, TRUE)
# result <- x %not_in% y
# expected <- c(TRUE, TRUE, TRUE)

expect_equal(result, expected)
# testthat::expect_equal(result, expected)

testthat::expect_warning(object = x %not_in% y)

x <- NULL
y <- c("apple", "banana")

result <- x %not_in% y
expected <- logical(0)
# result <- x %not_in% y
# expected <- logical(0)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})

test_that("`%not_in%` works with numeric edge cases", {
testthat::test_that("`%not_in%` works with numeric edge cases", {
x <- c(-1, 0, 1, Inf, -Inf, NA)
y <- c(0, NA, Inf)

result <- x %not_in% y
expected <- c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE)
# result <- x %not_in% y
# expected <- c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE)

# testthat::expect_equal(result, expected)

expect_equal(result, expected)
testthat::expect_warning(object = x %not_in% y)
})
Loading