checkarg (version 0.1.0)

isZeroOrNaScalarOrNull: Wrapper for the checkarg function, using specific parameter settings.

Description

This function can be used in 3 ways:
  1. Return TRUE or FALSE depending on whether the argument checks are passed. This is suitable e.g. for if statements that take further action if the argument does not pass the checks.
  2. Throw an exception if the argument does not pass the checks. This is suitable e.g. when no further action needs to be taken other than throwing an exception if the argument does not pass the checks.
  3. Same as (2) but by supplying a default value, a default can be assigned in a single statement, when the argument is NULL. The checks are still performed on the returned value, and an exception is thrown when not passed.

Usage

isZeroOrNaScalarOrNull(argument, default = NULL, stopIfNot = FALSE,
  message = NULL, argumentName = NULL)

Arguments

argument
See checkarg function.
default
See checkarg function.
stopIfNot
See checkarg function.
message
See checkarg function.
argumentName
See checkarg function.

Value

See checkarg function.

Details

Actual call to checkarg: checkarg(argument, "N", default = default, stopIfNot = stopIfNot, nullAllowed = TRUE, n = 1, zeroAllowed = TRUE, negativeAllowed = FALSE, positiveAllowed = FALSE, nonIntegerAllowed = TRUE, naAllowed = TRUE, nanAllowed = FALSE, infAllowed = FALSE, message = message, argumentName = argumentName)

Examples

Run this code
isZeroOrNaScalarOrNull(0)
   # returns TRUE (argument is valid)
isZeroOrNaScalarOrNull("X")
   # returns FALSE (argument is invalid)
#isZeroOrNaScalarOrNull("X", stopIfNot = TRUE)
   # throws exception with message defined by message and argumentName parameters
isZeroOrNaScalarOrNull(0, default = NA)
   # returns 0 (the argument, rather than the default, since it is not NULL)
#isZeroOrNaScalarOrNull("X", default = NA)
   # throws exception with message defined by message and argumentName parameters
isZeroOrNaScalarOrNull(NULL, default = NA)
   # returns NA (the default, rather than the argument, since it is NULL)

Run the code above in your browser using DataCamp Workspace