The R Project SVN R

Rev

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

Rev 68948 Rev 70602
Line 1... Line 1...
1
% File src/library/base/man/sink.Rd
1
% File src/library/base/man/sink.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-2015 R Core Team
3
% Copyright 1995-2016 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{sink}
6
\name{sink}
7
\alias{sink}
7
\alias{sink}
8
\alias{sink.number}
8
\alias{sink.number}
Line 24... Line 24...
24
    stream.  The name will be partially matched so can be abbreviated.}
24
    stream.  The name will be partially matched so can be abbreviated.}
25
  \item{split}{logical: if \code{TRUE}, output will be sent to the new
25
  \item{split}{logical: if \code{TRUE}, output will be sent to the new
26
    sink and to the current output stream, like the Unix program \code{tee}.}
26
    sink and to the current output stream, like the Unix program \code{tee}.}
27
}
27
}
28
\description{
28
\description{
29
  \code{sink} diverts \R output to a connection.
29
  \code{sink} diverts \R output to a connection (and stops such diversions).
30
 
30
 
31
  \code{sink.number()} reports how many diversions are in use.
31
  \code{sink.number()} reports how many diversions are in use.
32
 
32
 
33
  \code{sink.number(type = "message")} reports the number of the
33
  \code{sink.number(type = "message")} reports the number of the
34
  connection currently being used for error messages.
34
  connection currently being used for error messages.
35
}
35
}
36
\details{
36
\details{
37
  \code{sink} diverts \R output to a connection.  If \code{file} is a
37
  \code{sink} diverts \R output to a connection (and must be used again
-
 
38
  to finish such a diversion, see below!).  If \code{file} is a
38
  character string, a file connection with that name will be established
39
  character string, a file connection with that name will be established
39
  for the duration of the diversion.
40
  for the duration of the diversion.
40
 
41
 
41
  Normal \R output (to connection \code{\link{stdout}}) is diverted by
42
  Normal \R output (to connection \code{\link{stdout}}) is diverted by
42
  the default \code{type = "output"}.  Only prompts and (most)
43
  the default \code{type = "output"}.  Only prompts and (most)
Line 97... Line 98...
97
\examples{
98
\examples{
98
sink("sink-examp.txt")
99
sink("sink-examp.txt")
99
i <- 1:10
100
i <- 1:10
100
outer(i, i, "*")
101
outer(i, i, "*")
101
sink()
102
sink()
102
unlink("sink-examp.txt")
103
\dontshow{unlink("sink-examp.txt")}% don't show what confuses newbies
103
\donttest{
104
\donttest{
104
## capture all the output to a file.
105
## capture all the output to a file.
105
zz <- file("all.Rout", open = "wt")
106
zz <- file("all.Rout", open = "wt")
106
sink(zz)
107
sink(zz)
107
sink(zz, type = "message")
108
sink(zz, type = "message")
108
try(log("a"))
109
try(log("a"))
109
## back to the console
110
## revert output back to the console -- only then access the file!
110
sink(type = "message")
111
sink(type = "message")
111
sink()
112
sink()
112
file.show("all.Rout")
113
file.show("all.Rout")
113
}}
114
}}
114
\keyword{file}
115
\keyword{file}