Skip to content

Commit

Permalink
🚀 negated in function
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Jung committed Dec 5, 2024
1 parent 46b7421 commit 9acf673
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export("%notin%")
export(misc_sanitizeNames)
export(sp_replaceGriddedNA)
export(sp_resampleRas)
19 changes: 19 additions & 0 deletions R/misc_notIn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Inverse of 'in' call
#'
#' @description
#' Calculates the set of entries not present in the second vector.
#' Added for convenience since this is not supported by default in R.
#'
#' @param a First [`vector`] object.
#' @param b Second [`vector`] object.
#'
#' @returns A [`vector`] of [`logical`] entries of \code{'a'} not present in \code{'b'}.
#' @examples
#' # example code
# lu <- c("Forest", "Cropland", "Wetland", "OtherLand")
# lu2 <- c("Forest", "Wetland", "otherland")
# which(lu %notin% lu2)
#' @keywords utils
#' @author Martin Jung
#' @export
`%notin%` = function(a, b){!(a %in% b)}
27 changes: 27 additions & 0 deletions man/grapes-notin-grapes.Rd

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

8 changes: 7 additions & 1 deletion tests/testthat/test-misc_tests.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
test_that("Basic unit tests for misc functions", {
test_that("Basic unit tests for small misc functions", {
expect_equal(misc_sanitizeNames("Climate-temperature2015"), "Climate_temperature2015")

# Not in function\
lu <- c("Forest", "Cropland", "Wetland", "OtherLand")
lu2 <- c("Forest", "Wetland", "otherland")
test <- which(lu %notin% lu2)
expect_equal(test, c(2,4))
})

0 comments on commit 9acf673

Please sign in to comment.