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

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

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

                                        Transfer Character Strings To and From Connections
                                         将要和从连接字符串

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

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

Transfer character strings to and from connections, without assuming they are null-terminated on the connection.
从连接字符串传送,而假设他们是空终止连接。


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


readChar(con, nchars, useBytes = FALSE)

writeChar(object, con, nchars = nchar(object, type="chars"),
          eos = "", useBytes = FALSE)



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

参数:con
A connection object, or a character string naming a file, or a raw vector.
一个连接对象,或一个字符串,命名一个文件,或原始向量。


参数:nchars
integer, giving the lengths in characters of (unterminated) character strings to be read or written.  Must be >= 0 and not missing.
整数,使字符(未结束)字符被读取或写入字符串的长度。必须> = 0且没有丢失。


参数:useBytes
logical: For readChar, should nchars be regarded as a number of bytes not characters in a multi-byte locale?  For writeChar, see writeLines.  
逻辑:readChar,应nchars被视为一个多字节语言环境中的数量作为一个字节而不是字符? writeChar,看到writeLines。


参数:object
A character vector to be written to the connection, at least as long as nchars.
要写入的字符向量连接,至少为nchars。


参数:eos
"end of string": character string .  The terminator to be written after each string, followed by an ASCII nul; use NULL for no terminator at all.
“结束的字符串:字符串。 “终结者”被写入每个字符串后,由ASCIInul使用NULL没有终结所有。


Details

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

These functions complement readBin and writeBin which read and write C-style zero-terminated character strings.  They are for strings of known length, and can optionally write an end-of-string mark.  They are intended only for character strings valid in the current locale.
这些功能互补readBin和writeBin读写C风格的以零结尾的字符串。它们是已知长度的字符串,并可以随意写一个串结束标志。他们的目的只为在当前语言环境的有效字符串。

These functions are intended to be used with binary-mode connections. If con is a character string, the functions call file to obtain a binary-mode file connection which is opened for the duration of the function call.
这些功能的目的是要使用二进制模式连接。 con如果是一个字符串,函数调用file来获得函数调用的时间打开一个二进制模式文件连接。

If the connection is open it is read/written from its current position.  If it is not open, it is opened for the duration of the call in an appropriate mode (binary read or write) and then closed again.  An open connection must be in binary mode.
如果连接是打开的,它的读/写从当前位置。如果它是不开放的,它是开在一个适当的模式(二进制读或写)呼叫的持续时间,然后再次关闭。一个开放的连接,必须在二进制模式。

If readChar is called with con a raw vector, the data in the vector is used as input.  If writeChar is called with con a raw vector, it is just an indication that a raw vector should be returned.  
readChar如果被称为con原始向量,在向量中的数据作为输入使用。 writeChar如果被称为con原始的向量,它只是一个说明,应该返回原始向量。

Character strings containing ASCII nul(s) will be read correctly by readChar but truncated at the first nul with a warning.
字符串包含ASCII nul(S)将正确读取readChar,但在第一次nul截断警告。

If the character length requested for readChar is longer than the data available on the connection, what is available is returned.  For writeChar if too many characters are requested the output is zero-padded, with a warning.
如果字符长度readChar是长于数据连接,什么是可以要求返回。为writeChar如果要求太多字符的输出是零填充的警告。

Missing strings are written as NA.
失踪的字符串写入NA。


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

For readChar, a character vector of length the number of items read (which might be less than length(nchars)).
readChar,特征向量的长度读(这可能是比length(nchars))的项目数。

For writeChar, a raw vector (if con is a raw vector) or invisibly NULL.
writeChar,原始向量(con如果是原始向量)或无形NULL。


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

Earlier versions of R allowed embedded nul bytes within character strings, but not R >= 2.8.0.  readChar was commonly used to read fixed-size zero-padded byte fields for which readBin was unsuitable.  readChar can still be used for such fields if there are no embedded nuls: otherwise readBin(what="raw") provides an alternative.
R的早期版本允许在字符串内嵌入的NUL字节,但不是R> = 2.8.0。 readChar通常用于读取固定大小的零填充字节字段为readBin的是不合适的。 readChar还可以被用于等领域,如果没有嵌入式的nuls否则readBin(what="raw")提供了一种替代。

nchars will be interpreted in bytes not characters in a non-UTF-8 multi-byte locale, with a warning.
nchars将解释字节而不是字符的非UTF-8多字节语言环境中,一个警告。

There is little validity checking of UTF-8 reads.
很少有有效性检查的UTF-8读取。

Using these functions on a text-mode connection may work but should not be mixed with text-mode access to the connection, especially if the connection was opened with an encoding argument.
文本模式连接上使用这些功能可能工作,但不应混合文本模式访问连接,特别是如果连接被打开encoding参数。


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

The R Data Import/Export manual.
R数据导入/导出手册。

connections, readLines, writeLines, readBin
connections,readLines,writeLines,readBin


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


## test fixed-length strings[#测试固定长度的字符串]
zz <- file("testchar", "wb")
x <- c("a", "this will be truncated", "abc")
nc <- c(3, 10, 3)
writeChar(x, zz, nc, eos=NULL)
writeChar(x, zz, eos="\r\n")
close(zz)

zz <- file("testchar", "rb")
readChar(zz, nc)
readChar(zz, nchar(x)+3) # need to read the terminator explicitly[明确需要阅读的终结者]
close(zz)
unlink("testchar")

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 10:36 , Processed in 0.028830 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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