sink(base)
sink()所属R语言包:base
Send R Output to a File
发送R输出到一个文件
译者:生物统计家园网 机器人LoveR
描述----------Description----------
sink diverts R output to a connection.
sink转移R输出连接。
sink.number() reports how many diversions are in use.
sink.number()报告使用多少改道。
sink.number(type = "message") reports the number of the connection currently being used for error messages.
sink.number(type = "message")报告错误消息目前正在使用的连接数量。
用法----------Usage----------
sink(file = NULL, append = FALSE, type = c("output", "message"),
split = FALSE)
sink.number(type = c("output", "message"))
参数----------Arguments----------
参数:file
a writable connection or a character string naming the file to write to, or NULL to stop sink-ing.
一个可写的连接字符串命名的文件写入,或NULL停止下沉ING。
参数:append
logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file.
逻辑。如果TRUE,输出将被附加到file,否则,它会覆盖file内容。
参数:type
character. Either the output stream or the messages stream.
字符。无论是输出流的信息流。
参数:split
logical: if TRUE, output will be sent to the new sink and to the current output stream, like the Unix program tee.
逻辑:如果TRUE,输出将发送到新的接收器和电流输出流,如Unix程序tee。
Details
详情----------Details----------
sink diverts R output to a connection. If file is a character string, a file connection with that name will be established for the duration of the diversion.
sink转移R输出连接。如果file是一个字符串,该名称的文件将建立连接为引水期限。
Normal R output (to connection stdout) is diverted by the default type = "output". Only prompts and (most) messages continue to appear on the console. Messages sent to stderr() (including those from message, warning and stop) can be diverted by sink(type = "message") (see below).
正常R输出(连接stdout)默认type = "output"改行。仅提示(大多数)的消息继续出现在控制台上。消息发送到stderr()(包括那些来自message,warning和stop),可以改由sink(type = "message")(见下文)。
sink() or sink(file=NULL) ends the last diversion (of the specified type). There is a stack of diversions for normal output, so output reverts to the previous diversion (if there was one). The stack is of up to 21 connections (20 diversions).
sink()或sink(file=NULL)结束了最后的分流(指定类型)。有一摞正常输出改道,使输出恢复到以前的导流(如果有的话)。堆栈连接多达21个(20改道)。
If file is a connection it will be opened if necessary (in "wt" mode) and closed once it is removed from the stack of diversions.
file如果是一个连接,它会打开("wt"模式),如果有必要关闭,一旦改道栈中删除。
split = TRUE only splits R output (via Rvprintf) and the default output from writeLines: it does not split all output that might be sent to stdout().
split = TRUE分裂R输出(通过Rvprintf)和默认的输出从writeLines:它不分裂都可能被发送到stdout()输出。
Sink-ing the messages stream should be done only with great care. For that stream file must be an already open connection, and there is no stack of connections.
ING下沉的消息流,应做非常谨慎。该流file必须是一个已经打开的连接,并没有堆栈连接。
If file is a character string, the file will be opened using the current encoding. If you want a different encoding (e.g. to represent strings which have been stored in UTF-8), use a file connection — but some ways to produce R output will already have converted such strings to the current encoding.
file如果是一个字符串,该文件将被打开,使用目前的编码。如果你想要一个不同的编码(如代表已在UTF-8存储的字符串),使用file连接 - 但一些生产R输出的方式将已经转换这样的字符串到当前编码。
值----------Value----------
sink returns NULL.
sink返回NULL。
For sink.number() the number (0, 1, 2, ...) of diversions of output in place.
sink.number()到位输出改道(0,1,2,...)。
For sink.number("message") the connection number used for messages, 2 if no diversion has been used.
sink.number("message")的消息,2,如果没有改道已使用的连接数。
警告----------Warning----------
Do not use a connection that is open for sink for any other purpose. The software will stop you closing one such inadvertently.
不要使用连接sink用于任何其他目的是开放的。你关闭一个这样不经意间,该软件将停止。
Do not sink the messages stream unless you understand the source code implementing it and hence the pitfalls.
不下沉的消息流,除非你理解的源代码,执行它,因此陷阱。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
Programming with Data. A Guide to the S Language. Springer.
参见----------See Also----------
capture.output
capture.output
举例----------Examples----------
sink("sink-examp.txt")
i <- 1:10
outer(i, i, "*")
sink()
unlink("sink-examp.txt")
## Not run: [#无法运行:]
## capture all the output to a file.[#捕捉所有输出到一个文件中。]
zz <- file("all.Rout", open="wt")
sink(zz)
sink(zz, type="message")
try(log("a"))
## back to the console[#返回到控制台]
sink(type="message")
sink()
try(log("a"))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|