Skip to content

Commit

Permalink
add the == and != Ops for sgbp
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Apr 16, 2024
1 parent 32aa6c8 commit 7c4b154
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
24 changes: 17 additions & 7 deletions R/sgbp.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,27 @@ dim.sgbp = function(x) {
c(length(x), attr(x, "ncol"))
}

#' @name sgbp
#' @param e1 object of class `sgbp`
#' @param e2 object of class `sgbp`
#' @export
#' @details `==` compares only the dimension and index values, not the attributes of two `sgbp` object; use `identical` to check for equality of everything.
Ops.sgbp = function(e1, e2) {
if (.Generic != "!")
stop("only ! operator is supported for sgbp objects")
nc = 1:attr(e1, "ncol")
sgbp(lapply(e1, function(x) setdiff(nc, x)),
predicate = paste0("!", attr(e1, "predicate")),
region.id = attr(e1, "region.id"),
ncol = attr(e1, "ncol"))
switch(.Generic,
"!" = {
nc = 1:attr(e1, "ncol")
sgbp(lapply(e1, function(x) setdiff(nc, x)),
predicate = paste0("!", attr(e1, "predicate")),
region.id = attr(e1, "region.id"),
ncol = attr(e1, "ncol"))
},
"==" = (length(e1) == length(e2)) && all(mapply(function(x,y) identical(x, y), e1, e2)),
"!=" = return(!(e1 == e2)),
stop("only operators !, == and != are supported for sgbp objects")
)
}

#' @name sgbp
#' @export
as.data.frame.sgbp = function(x, ...) {
data.frame(row.id = rep(seq_along(x), lengths(x)), col.id = unlist(x))
Expand Down
12 changes: 12 additions & 0 deletions man/sgbp.Rd

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

0 comments on commit 7c4b154

Please sign in to comment.