rawr_ops: rawr operators

rawr_opsR Documentation

rawr operators

Description

Some useful binary operators.

Usage

x %ni% table

x %sinside% interval

x %winside% interval

x %inside% interval

a %==% b

a %||% b

object %:% range

Arguments

x

vector or NULL; the values to be matched

table

vector or NULL; the values to be matched against

interval

numeric vector of length two representing the interval

a, b

raw, logical, "number-like" vectors or objects

object

a named vector or list, a matrix or data frame

range

a numeric or character vector of length two with the indices or names from object, generally of the structure c(from, to)

Details

%ni% is the negation of %in%.

%winside% and %sinside% return a logical vector indicating if x is weakly or strongly inside interval. %inside% is an alias for %winside% to preserve existing code.

%==% is an operator combining the qualities of == and %in% to compare vectors in a pairwise manner which may include NAs.

%||% is useful for a function, f, that may return a value or NULL; however if NULL is the return value of f, it is desirable to return some other default value.

%:% is useful for obtaining a range of a vector (usually colnames or names of a matrix or data frame) by literal character strings rather than by index.

See Also

==, %in%, ||

Examples

## notin
1:5 %ni% 3:5


## weakly/strongly inside
c(0,4) %winside% c(0, 4)
c(0,4) %sinside% c(0, 4)

-5:5 %winside% c(0,5)
-5:5 %sinside% c(0,5)


## %in% plus ==
a <- c(1, NA, 2)
b <- c(2, NA, 1)
## not desired
a == b     # FALSE NA   FALSE
a %in% b   # TRUE  TRUE TRUE
## desired results
a %==% b   # FALSE TRUE FALSE


# NULL || TRUE   # error
NULL %||% TRUE   # TRUE


1:5 %:% c(3, 5)
letters %:% c('e', 'n')

## these are equivalent
mtcars %:% c('hp', 'vs')
mtcars %:% c(4, 8)
names(mtcars[, 4:8])


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.