sink diverts R output to a connection (and stops such diversions). sink.number() reports how many diversions are in use. sink.number(type = "message") reports the number of the connection currently being used for error messages.
sink(file = NULL, append = FALSE, type = c("output", "message"),
split = FALSE)<p></p><p>sink.number(type = c("output", "message"))</p>
| Parameter | Description |
|---|---|
file |
a writable connection or a character string naming the file to write to, or NULL to stop sink-ing. |
append |
logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file. |
type |
character string. Either the output stream or the messages stream. The name will be partially matched so can be abbreviated. |
split |
logical: if TRUE, output will be sent to the new sink and to the current output stream, like the Unix program tee. |
# NOT RUN {
sink("sink-examp.txt")
i <- 1:10
outer(i, i, "*")
sink()
# }
# NOT RUN {
<!-- % don't show what confuses newbies -->
# }
# NOT RUN {
## capture all the output to a file.
zz <- file("all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
## revert output back to the console -- only then access the file!
sink(type = "message")
sink()
file.show("all.Rout")
# }