找回密码
 注册
查看: 2146|回复: 0

R语言:textconnections()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 19:10:15 | 显示全部楼层 |阅读模式
textconnections(base)
textconnections()所属R语言包:base

                                        Text Connections
                                         文字连接

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Input and output text connections.
输入和输出的文字连接。


用法----------Usage----------


textConnection(object, open = "r", local = FALSE,
               encoding = c("", "bytes", "UTF-8"))

textConnectionValue(con)



参数----------Arguments----------

参数:object
character.  A description of the connection.  For an input this is an R character vector object, and for an output connection the name for the R character vector to receive the output, or NULL (for none).  
字符。一个连接的描述。对于一个输入,这是一个R字的矢量对象,和一个输出连接的R的特征向量来接收输出,或NULL(无)的名称。


参数:open
character.  Either "r" (or equivalently "") for an input connection or "w" or "a" for an output connection.
字符。要么"r"(或等价"")输入连接或输出连接"w"或"a"。


参数:local
logical.  Used only for output connections.  If TRUE, output is assigned to a variable in the calling environment.  Otherwise the global environment is used.
逻辑。仅用于输出连接。如果TRUE,输出分配给调用环境变量。否则,全球的环境使用。


参数:encoding
character.  Used only for input connections.  How marked strings in object should be handled: converted to the current locale, used byte-by-byte or translated to UTF-8.
字符。仅用于输入连接。在如何显着的弦object应处理:转换为当前的语言环境,采用字节逐字节或转换为UTF-8。


参数:con
An output text connection.
输出的文字连接。


Details

详情----------Details----------

An input text connection is opened and the character vector is copied at time the connection object is created, and close destroys the copy.  object should be the name of a character vector: however, short expressions will be accepted provided they deparse to less than 60 bytes.
打开一个输入文本连接和特征向量在时间的复制连接对象被创建,close破坏的副本。 object应该是一个特征向量的名字,然而,短期的表达式将被接受提供它们deparse小于60字节。

An output text connection is opened and creates an R character vector of the given name in the user's workspace or in the calling environment, depending on the value of the local argument.  This object will at all times hold the completed lines of output to the connection, and isIncomplete will indicate if there is an incomplete final line.  Closing the connection will output the final line, complete or not.  (A line is complete once it has been terminated by end-of-line, represented by "\n" in R.)   The output character vector has locked bindings (see lockBinding) until close is called on the connection.  The character vector can also be retrieved via textConnectionValue, which is the only way to do so if object = NULL.  If the current locale is detected as Latin-1 or UTF-8, non-ASCII elements of the character vector will be marked accordingly (see Encoding).
打开一个输出文本的连接,并创建一个给定的名称在用户的工作区,或在调用环境R字符向量,local参数值而定。这个对象在任何时候都将举行完成输出线连接,isIncomplete将表明,如果有一个不完整的最后一行。关闭连接,将输出的最后一行,或不完整的。 (A线是完整的,一旦它被终止行结束,代表由"\n"在R)输出特征向量已经锁定,直到lockBinding是绑定(见close)呼吁连接。特征向量,也可以通过textConnectionValue,这是唯一的出路,所以如果object = NULL检索。如果当前的语言环境检测的Latin-1或UTF-8,非ASCII字符向量元素将相应标记(见Encoding)。

Opening a text connection with mode = "a" will attempt to append to an existing character vector with the given name in the user's workspace or the calling environment.  If none is found (even if an object exists of the right name but the wrong type) a new character vector will be created, with a warning.
mode = "a"打开文本连接会尝试与用户的工作区或调用环境中给定的名称追加到现有的特征向量。如果没有找到(即使对象存在的权利的名称,但错误的类型)一个新的特征向量,将创建一个警告。

You cannot seek on a text connection, and seek will always return zero as the position.
你不能seek文本连接,seek将始终返回零的位置。

Text connections have slightly unusual semantics: they are always open, and throwing away an input text connection without closing it (so it get garbage-collected) does not give a warning.
文字连接有稍不寻常的语义:他们总是开放的,扔掉输入文字连接没有关闭(所以垃圾回收),不给予警告。


值----------Value----------

For textConnection, a connection object of class "textConnection" which inherits from class "connection".
textConnection,连接对象类"textConnection"这继承了类"connection"。

For textConnectionValue, a character vector.
对于textConnectionValue,字符向量。


注意----------Note----------

As output text connections keep the character vector up to date line-by-line, they are relatively expensive to use, and it is often better to use an anonymous file() connection to collect output.
作为输出文本连接的特征向量保持最新行线,他们是相对昂贵的使用,它往往是更好地使用匿名file()连接收集输出。

On (rare) platforms where vsnprintf does not return the needed length of output there is a 100,000 character limit on the length of line for output connections: longer lines will be truncated with a warning.
(罕见)平台vsnprintf不返回所需长度的输出有输出连接上的线路长度10万字符限制:更长的线将被截断警告。


参考文献----------References----------

Programming with Data.  A Guide to the S Language. Springer.<br> [S has input text connections only.]

参见----------See Also----------

connections, showConnections, pushBack, capture.output.
connections,showConnections,pushBack,capture.output。


举例----------Examples----------


zz <- textConnection(LETTERS)
readLines(zz, 2)
scan(zz, "", 4)
pushBack(c("aa", "bb"), zz)
scan(zz, "", 4)
close(zz)

zz <- textConnection("foo", "w")
writeLines(c("testit1", "testit2"), zz)
cat("testit3 ", file=zz)
isIncomplete(zz)
cat("testit4\n", file=zz)
isIncomplete(zz)
close(zz)
foo

## Not run: # capture R output: use part of example from help(lm)[#无法运行:#捕获R输出:使用范例的一部分,从“帮助”(LM)]
zz <- textConnection("foo", "w")
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.5, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
sink(zz)
anova(lm.D9 <- lm(weight ~ group))
cat("\nSummary of Residuals:\n\n")
summary(resid(lm.D9))
sink()
close(zz)
cat(foo, sep = "\n")

## End(Not run)[#结束(不运行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 08:53 , Processed in 0.023923 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表