setops: Set operations

setopsR Documentation

Set operations

Description

Performs set union, intersection, (asymmetric!) difference, and equality on two or more vector-like objects.

NOTE: This man page is for the union, intersect, setdiff, and setequal S4 generic functions defined in the BiocGenerics package. See ?generics::union for the default methods (defined in CRAN package generics). Bioconductor packages can define specific methods for objects (typically vector-like) not supported by the default methods.

Usage

union(x, y, ...)
intersect(x, y, ...)
setdiff(x, y, ...)
setequal(x, y, ...)

Arguments

x, y

Vector-like objects (typically of the same class, but not necessarily).

...

Additional arguments, for use in specific methods.

Value

See ?generics::union in CRAN package generics for the value returned by the default methods.

Specific methods defined in Bioconductor packages will typically act as endomorphisms, that is, they'll return an object of the same class as the input objects.

Note

The default S4 methods for these S4 generics are the union, intersect, setdiff, and setequal functions defined in CRAN package generics, which are themselves S3 generic functions. These S3 generics in turn have default methods that simply call the corresponding base R function i.e. the union, intersect, setdiff, or setequal function defined in the base package. See for example generics:::union.default.

Note that the base R functions only take 2 arguments. However, the S3 generics in CRAN package generics, and the S4 generics in BiocGenerics, add ... (a.k.a. ellipsis) to the argument list. This allow these generics to be called with an arbitrary number of effective arguments.

For union or intersect, this means that Bioconductor packages can implement N-ary union or intersection operations, that is, methods that compute the union or intersection of more than 2 objects.

However, for setdiff and setequal, which are conceptually binary-only operation, the presence of the ellipsis typically allows methods to support extra arguments to control/alter the behavior of the operation. Like for example the ignore.strand argument supported by the setdiff method for GenomicRanges objects (defined in the GenomicRanges package). (Note that the union and intersect methods for those objects also support the ignore.strand argument.)

See Also

  • generics::union for the default union, intersect, setdiff, and setequal S4 methods defined in CRAN package generics.

  • showMethods for displaying a summary of the methods defined for a given generic function.

  • selectMethod for getting the definition of a specific method.

  • union,GenomicRanges,GenomicRanges-method in the GenomicRanges package for examples of specific union, intersect, and setdiff methods (defined for GenomicRanges objects).

  • BiocGenerics for a summary of all the generics defined in the BiocGenerics package.

Examples

## ---------------------------------------------------------------------
## union()
## ---------------------------------------------------------------------

## S4 generic:
union  # note the dispath on 'x' and 'y'

showMethods("union")

## The default S4 method is an S3 generic function defined in
## CRAN package generics:
selectMethod("union", c("ANY", "ANY"))

## The default S3 method just calls base::union():
generics:::union.default

## ---------------------------------------------------------------------
## intersect()
## ---------------------------------------------------------------------

## S4 generic:
intersect  # note the dispath on 'x' and 'y'

showMethods("intersect")

## The default S4 method is an S3 generic function defined in
## CRAN package generics:
selectMethod("intersect", c("ANY", "ANY"))

## The default S3 method just calls base::intersect():
generics:::intersect.default

## ---------------------------------------------------------------------
## setdiff()
## ---------------------------------------------------------------------

## S4 generic:
setdiff  # note the dispath on 'x' and 'y'

showMethods("setdiff")

## The default S4 method is an S3 generic function defined in
## CRAN package generics:
selectMethod("setdiff", c("ANY", "ANY"))

## The default S3 method just calls base::setdiff():
generics:::setdiff.default

## ---------------------------------------------------------------------
## setequal()
## ---------------------------------------------------------------------

## S4 generic:
setequal  # note the dispath on 'x' and 'y'

showMethods("setequal")

## The default S4 method is an S3 generic function defined in
## CRAN package generics:
selectMethod("setequal", c("ANY", "ANY"))

## The default S3 method just calls base::setequal():
generics:::setequal.default

Bioconductor/BiocGenerics documentation built on Nov. 17, 2024, 6:52 p.m.