Generate a warning message.
The warning() function generates a warning message that is displayed to the user but does not stop execution. Warnings are used to flag potential issues without interrupting the computation.
warning messages are collected during execution and can be reviewed with warnings(). The global option warn controls when warnings are displayed: 0 collects them, 1 prints them immediately, and 2 converts them to errors.
| Name | Description | Optional |
|---|---|---|
... |
Zero or more objects coerced to character and pasted together to form the warning message. | No |
call. |
If TRUE (default), the call is included in the warning message. | Yes |
immediate. |
If TRUE, the warning is output immediately even when warn = 0. | Yes |
warning("NAs introduced by coercion")
if (n < 10) warning("small sample size: n = ", n)
options(warn = 2) # treat warnings as errors