[ 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)

#  warnings: Print Warning Messages

##  Description

` warnings ` and its ` print ` method print the variable ` last.warning ` in a
pleasing form.

##  Usage

    
    
    warnings(…)
    
    # S3 method for warnings
    summary(object, …)
    
    # S3 method for warnings
    print(x, tags,
          header = ngettext(n, "Warning message:\n", "Warning messages:\n"),
          …)
    # S3 method for summary.warnings
    print(x, …)

##  Arguments

…

arguments to be passed to ` [ cat ](/link/cat?package=base&version=3.6.2) `
(for ` warnings() ` ).

object

a ` "warnings" ` object as returned by ` warnings() ` .

x

a ` "warnings" ` or ` "summary.warnings" ` object.

tags

if not ` [ missing ](/link/missing?package=base&version=3.6.2) ` , a ` [
character ](/link/character?package=base&version=3.6.2) ` vector of the same `
[ length ](/link/length?package=base&version=3.6.2) ` as ` x ` , to “label”
the messages. Defaults to ` paste0(seq_len(n), ": ") ` for \\(n \ge 2\\) where
` n <- length(x) ` .

header

a character string ` [ cat ](/link/cat?package=base&version=3.6.2) () ` ed
before the messages are printed.

##  Value

` warnings() ` returns an object of S3 class ` "warnings" ` , basically a
named ` [ list ](/link/list?package=base&version=3.6.2) ` .

` summary(<warnings>) ` returns a ` "summary.warnings" ` object which is
basically the ` [ list ](/link/list?package=base&version=3.6.2) ` of unique
warnings ( ` unique(object) ` ) with a ` "counts" ` attribute, somewhat
experimentally.

##  Warning

It is undocumented where ` last.warning ` is stored nor that it is visible,
and this is subject to change.

##  Details

See the description of ` [ options ](/link/options?package=base&version=3.6.2)
("warn") ` for the circumstances under which there is a ` last.warning `
object and ` warnings() ` is used. In essence this is if ` options(warn = 0) `
and ` warning ` has been called at least once.

Note that the ` [ length ](/link/length?package=base&version=3.6.2)
(last.warning) ` is maximally ` [ getOption
](/link/getOption?package=base&version=3.6.2) ("nwarnings") ` (at the time the
warnings are generated) which is ` 50 ` by default. To increase, use something
like

    
    
      options(nwarnings = 10000)  

It is possible that ` last.warning ` refers to the last recorded warning and
not to the last warning, for example if ` options(warn) ` has been changed or
if a catastrophic error occurred.

##  References

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

##  See Also

` [ warning ](/link/warning?package=base&version=3.6.2) ` .

##  Examples

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

    
    
    # NOT RUN {
    ## NB this example is intended to be pasted in,
    ##    rather than run by example()
    ow <- options("warn")
    for(w in -1:1) {
       options(warn = w); cat("\n warn =", w, "\n")
       for(i in 1:3) { cat(i,"..\n"); m <- matrix(1:7, 3,4) }
       cat("--=--=--\n")
    }
    ## at the end prints all three warnings, from the 'option(warn = 0)' above
    options(ow) # reset to previous, typically 'warn = 0'
    tail(warnings(), 2) # see the last two warnings only (via '[' method)
    
    ## Often the most useful way to look at many warnings:
    summary(warnings())
    # }
    # NOT RUN {
    op <- options(nwarnings = 10000) ## <- get "full statistics"
    x <- 1:36; for(n in 1:13) for(m in 1:12) A <- matrix(x, n,m) # There were 105 warnings ...
    summary(warnings())
    options(op) # revert to previous (keeping 50 messages by default)
    # }