combine: Combination of is* conditions

Description Usage Arguments Details Examples

Description

Logical tests as defined by is* functions can be combined by the standard logical operators &, |, and xor.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S3 method for class 'IsFunction'
x & y

## S3 method for class 'IsFunction'
x | y

## S3 method for class 'IsFunction'
xor(x, y)

xor(x, y)

## Default S3 method:
xor(x, y)

Arguments

x, y

two logical statements (is functions) which should be combined

Details

If both tests are strict tests (that is, they were called by setting 'strict.' to TRUE [the default], which can be checked by isStrict), the tests are combined in the standard fashion.
However, if at least one of the tests is optional (strict. = FALSE), the combined result is going to be returned by the new test only if it contains at least one TRUE value. Otherwise, it will return the result of the strict test alone, or if both tests are optional, only FALSE values will be returned.
Note that xor has been made generic and a new xor.default method was added besides xor.IsFunction. The new default method is much faster than base::xor and is authored by Jens Oehlschlagel (see ?xor in package bit).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# define two strict constraints and combine them
check_above_10 <- isBetween(lwr. = 10, open. = "lwr")
check_local_max <- isLocalMaximum()
check_local_max_above_10 <- check_local_max & check_above_10

# call the combined test on the following vector
vec <- c(0, 1, 0, 11, 0, 21, 0)
( res <- check_local_max_above_10(vec) )
stopifnot(identical(
    c(res),
    c(FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE)
))

# make the above_10 constraint optional
check_maybe_above_10 <- isBetween(lwr. = 10, open. = "lwr", strict. = FALSE)
check_local_max_maybe_above_10 <- check_local_max & check_maybe_above_10

# call the combined test on the vector
( res2 <- check_local_max_maybe_above_10(vec) )

# the results are identical, because the combined test is TRUE for at least
# one data point
stopifnot(identical(
    c(res), c(res2)
))

# now change the test vector with no local maximum above 10,
# and run the test
vec3 <- c(0, 1, 0)
( res3 <- check_local_max_maybe_above_10(vec3) )

# here, the optional test is ignored
stopifnot(identical(
    res3, check_local_max(vec3)
))

tdeenes/eegR documentation built on April 19, 2021, 4:17 p.m.