allTrue: Test whether all expressions return TRUE

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This is typically used to combine multiple all.equal tests into a single test, in a test file called by do.test.

Usage

1

Arguments

...

Each argument is typically a call to do.test or another expression that returns a logical value.

Details

This is intended for use in test run by do.test. A typical test may contain lines that create one or more objects, followed by commands to check that those objects have the expected structure and/or that calculations were correct. By using allTrue, the tests can all be combined into the same expression that created the objects, so that if an error occurs it is easier to see where it occured.

Value

if all inputs are TRUE the value is TRUE. Otherwise a list indicating which arguments did not return TRUE, containing the actual values.

Author(s)

Tim Hesterberg

See Also

all.equal, do.test, expectStop, expectWarnings, identical.

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
# This is the type of expression that may be found in a test file
# to be run by do.test -- inside {} are lines that create one or
# more objects, followed by multiple tests (inside allTrue) that
# check those objects.
{
  y <- rnorm(30)
  x <- matrix(rnorm(60), ncol=2)
  fit <- lm(y~x)
  allTrue(# are important components included?
          all(is.element(c("coefficients", "residuals", "effects", "rank",
                           "fitted.values", "assign", "df.residual", "call"),
                         names(fit))),
          {
            # do coefficients match the algebraic form?
            # The algebraic form is inaccurate, so allow greater tolerance
            X <- cbind(1, x)
            all.equal(unname(fit$coefficients),
                      drop(solve( t(X) %*% X, t(X) %*% y)),
                      tol = 1e-5)
          },
          # are residuals computed correctly?
          all.equal(fit$residuals, y - X %*% fit$coefficients))
}
# The second test uses 'unname' to remove names and 'drop' to change a
# matrix to a vector, so the test should pass.
# The third test fails because fit$residuals is a vector with names
# while the %*% calculation returns a matrix.

splus2R documentation built on May 2, 2019, 5:24 p.m.

Related to allTrue in splus2R...