Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

strictOp

Apply strict conditions to R operators


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

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

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

Functions and Examples for "Software for Data Analysis"

v1.0-6.1
GPL (>= 2)
Authors
John M Chambers
Initial release
2014-06-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.