stop
additionally causes the function
to be exited.
stop(...) warning(...)
stop
prints the name of the function
calling
stop
,
followed by the error message,
then terminates execution of the current expression and creates a dump.
If the message is omitted, the expression is terminated (and dumped) silently.
warning
prints a similar warning message
at the end of evaluation of the expression,
but does not affect execution.
If too many warning messages are generated in one
expression (currently more than five),
the messages are stored together in an object in the working directory
named
last.warning
.
Only the number of warnings is then printed.
The function
warnings
will print out
the stored messages.
The
error
option
(see
options
)
specifies the action to be taken when a dump occurs;
the two main choices are discussed
in the
dump.calls
help file.
The
warn
option controls the behavior
when a warning is encountered.
Actions range from ignoring the warning message totally
(
warn=-1
),
generating the message at the end of the top level expression
(
warn=0
),
generating the message immediately (
warn=1
),
or causing the warning to behave
as an error (
warn=2
).
Two techniques useful for preventing errors during loops or other
long calculations from losing all intermediate results are to:
(1) save intermediate
results using
assign
(use
immediate=T
),
and (2) trap errors using
try
.
warning("Rank is ", n, " should be ", ncol(x)) if(any(is.na(x))) stop("NAs are not allowed in x")