[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  warning: Warning Messages

##  Description

Generates a warning message that corresponds to its argument(s) and
(optionally) the expression or function from which it was called.

##  Usage

    
    
    warning(…, call. = TRUE, immediate. = FALSE, noBreaks. = FALSE,
            domain = NULL)
    suppressWarnings(expr)

##  Arguments

…

zero or more objects which can be coerced to character (and which are pasted
together with no separator) or a single condition object.

call.

logical, indicating if the call should become part of the warning message.

immediate.

logical, indicating if the call should be output immediately, even if ` [
getOption ](/link/getOption?package=base&version=3.6.2) ("warn") <= 0 ` .

noBreaks.

logical, indicating as far as possible the message should be output as a
single line when ` options(warn = 1) ` .

expr

expression to evaluate.

domain

see ` [ gettext ](/link/gettext?package=base&version=3.6.2) ` . If ` NA ` ,
messages will not be translated, see also the note in ` [ stop
](/link/stop?package=base&version=3.6.2) ` .

##  Value

The warning message as ` [ character
](/link/character?package=base&version=3.6.2) ` string, invisibly.

##  Details

The result _depends_ on the value of ` [ options
](/link/options?package=base&version=3.6.2) ("warn") ` and on handlers
established in the executing code.

If a condition object is supplied it should be the only argument, and further
arguments will be ignored, with a message.

` warning ` signals a warning condition by (effectively) calling `
signalCondition ` . If there are no handlers or if all handlers return, then
the value of ` warn = [ getOption
](/link/getOption?package=base&version=3.6.2) ("warn") ` is used to determine
the appropriate action. If ` warn ` is negative warnings are ignored; if it is
zero they are stored and printed after the top--level function has completed;
if it is one they are printed as they occur and if it is 2 (or larger)
warnings are turned into errors. Calling ` warning(immediate. = TRUE) ` turns
` warn <= 0 ` into ` warn = 1 ` for this call only.

If ` warn ` is zero (the default), a read-only variable ` last.warning ` is
created. It contains the warnings which can be printed via a call to ` [
warnings ](/link/warnings?package=base&version=3.6.2) ` .

Warnings will be truncated to ` [ getOption
](/link/getOption?package=base&version=3.6.2) ("warning.length") ` characters,
default 1000, indicated by ` [... truncated] ` .

While the warning is being processed, a ` muffleWarning ` restart is
available. If this restart is invoked with ` invokeRestart ` , then ` warning
` returns immediately.

An attempt is made to coerce other types of inputs to ` warning ` to character
vectors.

` suppressWarnings ` evaluates its expression in a context that ignores all
warnings.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ stop ](/link/stop?package=base&version=3.6.2) ` for fatal errors, ` [
message ](/link/message?package=base&version=3.6.2) ` for diagnostic messages,
` [ warnings ](/link/warnings?package=base&version=3.6.2) ` , and ` [ options
](/link/options?package=base&version=3.6.2) ` with argument ` warn= ` .

` [ gettext ](/link/gettext?package=base&version=3.6.2) ` for the mechanisms
for the automated translation of messages.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fwarning&utm_source=r-docs&utm_medium=docs&utm_term=warning&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    testit <- function() warning("testit")
    testit() ## shows call
    testit <- function() warning("problem in testit", cal