splus2R (version 1.2-2)

allTrue: Test whether all expressions return TRUE

Description

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

Usage

allTrue(...)

Arguments

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

Value

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

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.

See Also

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

Examples

Run this code
# NOT RUN {
# 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.
# }

Run the code above in your browser using DataCamp Workspace