stop
Error and Warning Messages

Description

Issues an error or warning message from a function. Additionally, stop causes the function to be exited.

Usage

stop(..., call. = TRUE, domain = NULL)
warning(..., call. = TRUE, immediate. = FALSE, domain = NULL)
suppressWarnings(expr, classes = "warning")
suppressUnimplementedGraphicsWarnings(expr, call = sys.call(-1), showCount = TRUE)
geterrmessage()

Arguments

... zero or more objects that can be converted to characters, or one single condition object.
call. a logical flag. If TRUE (the default), the call is added to the stop or warning message.
domain The domain specifying the language for translating the message. If NA, messages are not translated.
immediate. a logical flag. If TRUE, the warning is output immediately. The default is FALSE.
expr the expression to evaluate.
classes a vector of class names.
call a call object. The first few characters of the text representation of this call will be put after "Warning message: In" when printing the warning message. The default is the call to the caller of suppressUnimplementedGraphicsWarnings.
showCount a logical value. If TRUE (the default) and there were some unimplemented-graphics warnings, suppressUnimplementedGraphicsWarnings will emit a warning saying how many there were. Otherwise it will totally suppress unimplemented-graphics warnings.

Details

It is possible to specify more complex behavior when an error or warning occurs using the condition system, via functions such as withCallingHandlers and tryCatch. If a condition object is passed as the only argument to stop or warning, it is used to signal the event, rather than constructing a simpleError or simpleWarning condition object.
Value
stopdoes not have a return value because it terminates executing the current expression.
warninginvisibly returns the warning message as a string.
suppressWarningsreturns the value of expr.
suppressUnimplementedGraphicsWarningsreturns the value of expr.
geterrmessagereturns the last error message, or the empty string if there is no error occured.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
warnings, options, stopifnot, try
Examples
# save any warnings
options(warn=0)

# generate warnings x <- seq(-5,5) # positive and negative numbers srx <- sqrt(x) if (any(is.nan(srx))) warning("srx contains NaNs!")

# print saved warnings warnings()

# generate error M <- matrix(1:4, nrow=2) if (!isSymmetric(M)) { stop("The matrix M is not symmetric!") } # get last error message geterrmessage()

Package base version 6.0.0-69
Package Index