strictOp: Apply strict conditions to R operators

Description Usage Arguments Details Value Examples

View source: R/strictOp.R

Description

The expression is checked for stricter conditions on compatible arguments; if the conditions fail an error or warning is issued. If no error is issued, the expression's value is returned.

Usage

1
2
withStrictOps(expr, attach)
strictOp(expr, warnOnly = FALSE, errorCall)

Arguments

expr

For withStrictOps, any expression to be evaluated. Subexpressions from the binary operators in the base package for arithmetic, comparison, and logic will be evaluated by stricter rules. For strictOp, the expression should only be one of these calls. Generally, withStrictOp will be more convenient to use, and strictOp is largely for internal use.

attach

No longer supported in CRAN, because of restriction added long after this package was written. Used to be:

Optional argument, only examined if expr is missing. If TRUE, then the "strictOps" environment is attached, overriding the applicable operators with strict versions. If attach is FALSE, this environment is detached. See the details.

warnOnly

If TRUE, only issue warnings on failures.

errorCall

Optional argument for internal use, supplying the expression to be used in error messages as the original call.

Details

The functions apply the stricter rules for compatibility given in section 7.1 of “Software for Data Analysis”.

Calling withStrictOps evaluates an arbitrary expression with an environment containing strict versions of all the relevant operators. Calling withStrictOps with no arguments attaches this environment to the search list, overriding the base versions of the operators. If the expressions pass the strict rules, evaluation is passed on to the corresponding base package version of the operator.

Value

the value of expr

Examples

1
2
3
sum(rnorm(3) ==  as.raw(1:3))# succeeds but comparison is ambiguous
muststop(withStrictOps(sum(rnorm(3) ==  as.raw(1:3))),
          silent = FALSE)  # signals an error

SoDA documentation built on Oct. 28, 2020, 9:07 a.m.