The R Project SVN R

Rev

Rev 71045 | Rev 88581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 71045 Rev 72553
Line 1... Line 1...
1
% File src/library/base/man/warnings.Rd
1
% File src/library/base/man/warnings.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2016 R Core Team
3
% Copyright 1995-2017 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{warnings}
6
\name{warnings}
7
\title{Print Warning Messages}
7
\title{Print Warning Messages}
8
\alias{warnings}
8
\alias{warnings}%%--> ../R/warnings.R
9
\alias{last.warning}
9
\alias{last.warning}
10
\alias{print.warnings}
10
\alias{print.warnings}
11
\alias{[.warnings}
11
\alias{[.warnings}
12
\alias{c.warnings}
12
\alias{c.warnings}
13
\alias{duplicated.warnings}
13
\alias{duplicated.warnings}
14
\alias{unique.warnings}
14
\alias{unique.warnings}
-
 
15
\alias{summary.warnings}
-
 
16
\alias{print.summary.warnings}
15
\description{
17
\description{
16
  \code{warnings} and its \code{print} method print the
18
  \code{warnings} and its \code{print} method print the
17
  variable \code{last.warning} in a pleasing form.
19
  variable \code{last.warning} in a pleasing form.
18
}
20
}
19
\usage{
21
\usage{
20
warnings(\dots)
22
warnings(\dots)
-
 
23
 
-
 
24
\S3method{summary}{warnings}(object, \dots)
-
 
25
 
-
 
26
\S3method{print}{warnings}(x, tags,
-
 
27
      header = ngettext(n, "Warning message:\n", "Warning messages:\n"),
-
 
28
      \dots)
-
 
29
\S3method{print}{summary.warnings}(x, \dots)
21
}
30
}
22
\arguments{
31
\arguments{
23
  \item{\dots}{arguments to be passed to \code{\link{cat}}.}
32
  \item{\dots}{arguments to be passed to \code{\link{cat}} (for
-
 
33
    \code{warnings()}).}
-
 
34
  \item{object}{a \code{"warnings"} object as returned by
-
 
35
    \code{warnings()}.}
-
 
36
  \item{x}{a \code{"warnings"} or \code{"summary.warnings"} object.}
-
 
37
  \item{tags}{if not \code{\link{missing}}, a \code{\link{character}}
-
 
38
    vector of the same \code{\link{length}} as \code{x}, to \dQuote{label}
-
 
39
    the messages.  Defaults to \code{paste0(seq_len(n), ": ")} for
-
 
40
    \eqn{n \ge 2}{n >= 2} where \code{n <- length(x)}.}
-
 
41
  \item{header}{a character string \code{\link{cat}()}ed before the
-
 
42
      messages are printed.}
24
}
43
}
25
\references{
44
\references{
26
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
45
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
27
  \emph{The New S Language}.
46
  \emph{The New S Language}.
28
  Wadsworth & Brooks/Cole.
47
  Wadsworth & Brooks/Cole.
Line 47... Line 66...
47
  visible, and this is subject to change.
66
  visible, and this is subject to change.
48
}
67
}
49
\seealso{
68
\seealso{
50
  \code{\link{warning}}.
69
  \code{\link{warning}}.
51
}
70
}
52
\value{an object of S3 class \code{"warnings"}, basically a named
71
\value{\code{warnings()} returns an object of S3 class \code{"warnings"}, basically a named
53
  \code{\link{list}}.
72
  \code{\link{list}}.
-
 
73
 
-
 
74
  \code{summary(<warnings>)} returns a \code{"summary.warnings"}
-
 
75
  object which is basically the \code{\link{list}} of unique warnings
-
 
76
  (\code{unique(object)}) with a \code{"counts"} attribute, somewhat
-
 
77
  experimentally.
54
}
78
}
55
\examples{
79
\examples{
56
## NB this example is intended to be pasted in,
80
## NB this example is intended to be pasted in,
57
##    rather than run by example()
81
##    rather than run by example()
58
ow <- options("warn")
82
ow <- options("warn")
59
for(w in -1:1) {
83
for(w in -1:1) {
60
   options(warn = w); cat("\n warn =", w, "\n")
84
   options(warn = w); cat("\n warn =", w, "\n")
61
   for(i in 1:3) { cat(i,"..\n"); m <- matrix(1:7, 3,4) }
85
   for(i in 1:3) { cat(i,"..\n"); m <- matrix(1:7, 3,4) }
-
 
86
   cat("--=--=--\n")
62
}
87
}
63
warnings()
88
## at the end prints all three warnings, from the 'option(warn = 0)' above
64
options(ow) # reset
89
options(ow) # reset to previous, typically 'warn = 0'
65
tail(warnings(), 2) # see the last two warnings only (via '[' method)
90
tail(warnings(), 2) # see the last two warnings only (via '[' method)
-
 
91
 
-
 
92
## Often the most useful way to look at many warnings:
-
 
93
summary(warnings())
66
\dontshow{
94
\dontshow{
67
ww <- warnings()
95
ww <- warnings()
68
uw <- unique(ww)
96
uw <- unique(ww)
-
 
97
sw <- summary(ww)
69
stopifnot(identical(c(ww[1], ww[3]), ww[c(1, 3)]),
98
stopifnot(identical(c(ww[1], ww[3]), ww[c(1, 3)]),
70
          length(uw) == 1, nchar(names(uw)) > 10)
99
          length(uw) == 1, nchar(names(uw)) > 10,
-
 
100
          length(sw) == 1, attr(sw, "counts") == 3)
71
}
101
}
-
 
102
op <- options(nwarnings = 10000) ## <- get "full statistics"
-
 
103
x <- 1:36; for(n in 1:13) for(m in 1:12) A <- matrix(x, n,m) # There were 105 warnings ...
-
 
104
summary(warnings())
-
 
105
options(op) # revert to previous (keeping 50 messages by default)
72
}
106
}
73
\keyword{programming}
107
\keyword{programming}
74
\keyword{error}
108
\keyword{error}