Skip to content

Commit

Permalink
Merge pull request #44 from ecohealthalliance/patch/set_diff
Browse files Browse the repository at this point in the history
Patch/set diff
  • Loading branch information
collinschwantes authored Aug 5, 2024
2 parents 63a26d8 + d2aa1b7 commit d98abe1
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ohcleandat
Type: Package
Title: One Health Data Cleaning and Quality Checking Package
Version: 0.3.0
Version: 0.3.1
Authors@R: c(
person("Collin", "Schwantes", email = "schwantes@ecohealthalliance.org", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-4014-4896")),
person("Johana", "Teigen", email = "teigen@ecohealthalliance.org", role = "aut", comment = c(ORCID = "0000-0002-6209-2321")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(othertext_lookup)
export(read_excel_all_sheets)
export(read_googlesheets)
export(remove_deletions)
export(set_diff)
export(validation_checks)
importFrom(dplyr,"%>%")
importFrom(rlang,":=")
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ohcleandat 0.3.1

* Explicitly adding `set_diff` function which was previously a hidden dependency on the {ecohealthalliance/airtabler} package

# ohcleandat 0.3.0

* Adding GPS obfuscation function - this function uses two methods to reduce the
Expand Down
37 changes: 37 additions & 0 deletions R/set_diff.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Get items that differ between x and y
#'
#' Unlike setdiff, this function creates the union of x and y then
#' removes values that are in the intersect, providing values
#' that are unique to X and values that are unique to Y.
#'
#' @param x a set of values.
#' @param y a set of values.
#'
#' @return Unique values from X and Y, NULL if no unique values.
#' @export
#'
#' @examples
#' a <- 1:3
#' b <- 2:4
#'
#' set_diff(a,b)
#' # returns 1,4
#'
#' x <- 1:3
#' y <- 1:3
#'
#' set_diff(x,y)
#' # returns NULL
#'
set_diff <- function(x,y){
u <- union(x,y)
i <- intersect(x,y)
j <- (u %in% i)

if(all(j)){
return(NULL)
}

diff <- u[!(j)]
return(diff)
}
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ utils::globalVariables(
"log_response_id",
"n",
"rowid",
"set_diff",
"entry_field",
"entry_field_dupe"
)
Expand Down
35 changes: 35 additions & 0 deletions man/set_diff.Rd

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

0 comments on commit d98abe1

Please sign in to comment.