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

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

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

                                        Transfer Binary Data To and From Connections
                                         要与从连接二进制数据传输

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

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

Read binary data from a connection, or write binary data to a connection.
从连接中读取二进制数据,或写入二进制数据连接。


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


readBin(con, what, n = 1L, size = NA_integer_, signed = TRUE,
        endian = .Platform$endian)

writeBin(object, con, size = NA_integer_,
         endian = .Platform$endian, useBytes = FALSE)



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

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


参数:what
Either an object whose mode will give the mode of the vector to be read, or a character vector of length one describing the mode: one of "numeric", "double", "integer", "int", "logical", "complex", "character", "raw".  
要么一个对象,其模式将要读取的矢量模式或特征向量的长度描述一个模式:"numeric","double","integer",<X >,"int","logical","complex","character"。


参数:n
integer.  The (maximal) number of records to be read.  You can use an over-estimate here, but not too large as storage is reserved for n items.
整数。要读的记录(最大)数目。你可以在这里使用过估计,但不会太大作为存储n项目。


参数:size
integer.  The number of bytes per element in the byte stream.  The default, NA_integer_, uses the natural size. Size changing is not supported for raw and complex vectors.
整数。在字节流中的每个元素的字节数。默认情况下,NA_integer_,使用天然的大小。不支持原材料和复杂的向量大小变化。


参数:signed
logical.  Only used for integers of sizes 1 and 2, when it determines if the quantity on file should be regarded as a signed or unsigned integer.
逻辑。仅用于尺寸1和2,当它决定,如果对文件的数量应作为一个符号或无符号整数的整数。


参数:endian
The endian-ness ("big" or "little" of the target system for the file.  Using "swap" will force swapping endian-ness.
尾数性("big"或"little"目标文件系统。使用"swap"将迫使交换尾数性。


参数:object
An R object to be written to the connection.
被写入到连接一个R对象。


参数:useBytes
See writeLines.  
看到writeLines。


Details

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

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

If size is specified and not the natural size of the object, each element of the vector is coerced to an appropriate type before being written or as it is read.  Possible sizes are 1, 2, 4 and possibly 8 for integer or logical vectors, and 4, 8 and possibly 12/16 for numeric vectors.  (Note that coercion occurs as signed types except if signed = FALSE when reading integers of sizes 1 and 2.) Changing sizes is unlikely to preserve NAs, and the extended precision sizes are unlikely to be portable across platforms.
如果size指定,而不是自然对象的大小,向量的每个元素被强制之前被写入适当的类型,或因为它是只读。可能的大小为1,2,4和8可能为整数或逻辑的向量,4,8和数字向量可能是12/16。 (请注意,胁迫,除非发生作为签署的类型signed = FALSE阅读时尺寸1和2的整数)。改变大小是不可能保持NA的和扩展精度的大小,是不太可能跨平台移植。

readBin and writeBin read and write C-style zero-terminated character strings.  Input strings are limited to 10000 characters.  readChar and writeChar can be used to read and write fixed-length strings.  No check is made that the string is valid in the current locale.
readBin和writeBin读写C风格的以零结尾的字符串。输入字符串限制为10000个字符。 readChar和writeChar可以用来读取和写入固定长度的字符串。该字符串是有效的在当前语言环境,没有检查。

Handling R's missing and special (Inf, -Inf and NaN) values is discussed in the R Data Import/Export manual.
处理R的丢失和特殊(Inf,-Inf和NaN)值在R数据导入/导出手册讨论。

Only 2^31 - 1 bytes can be written in a single call (and that is the maximum capacity of a raw vector).
只有2^31 - 1字节可以写在一个单一的通话(这是一个原始向量最大容量)。


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

For readBin, a vector of appropriate mode and length the number of items read (which might be less than n).
readBin,一个适当的模式和长度读(这可能是比n少)的项目数的向量。

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


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

Integer read/writes of size 8 will be available if either C type long is of size 8 bytes or C type long long exists and is of size 8 bytes.
如果采用C型long是8个字节或C型long long存在大小和大小是8字节整数读/写大小为8将提供。

Real read/writes of size sizeof(long double) (usually 12 or 16 bytes) will be available only if that type is available and different from double.
真正的读/写大小sizeof(long double)(通常为12或16个字节),将是可用的,只有当该类型是从double不同。

If readBin(what = character()) is used incorrectly on a file which does not contain C-style character strings, warnings (usually many) are given.  From a file or connection, the input will be broken into pieces of length 10000 with any final part being discarded.
如果readBin(what = character())使用上的文件,该文件不包含C风格的字符串,警告(通常是许多)不正确。从一个文件或连接,输入将被分成长度10000件,与任何被丢弃的最后一部分。

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数据导入/导出手册。

readChar to read/write fixed-length strings.
readChar读/写固定长度的字符串。

connections, readLines, writeLines.
connections,readLines,writeLines。

.Machine for the sizes of long, long long and long double.
.Machinelong,long long和long double的大小。


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


zz <- file("testbin", "wb")
writeBin(1:10, zz)
writeBin(pi, zz, endian="swap")
writeBin(pi, zz, size=4)
writeBin(pi^2, zz, size=4, endian="swap")
writeBin(pi+3i, zz)
writeBin("A test of a connection", zz)
z <- paste("A very long string", 1:100, collapse=" + ")
writeBin(z, zz)
if(.Machine$sizeof.long == 8 || .Machine$sizeof.longlong == 8)
    writeBin(as.integer(5^(1:10)), zz, size = 8)
if((s <-.Machine$sizeof.longdouble) > 8)
    writeBin((pi/3)^(1:10), zz, size = s)
close(zz)

zz <- file("testbin", "rb")
readBin(zz, integer(), 4)
readBin(zz, integer(), 6)
readBin(zz, numeric(), 1, endian="swap")
readBin(zz, numeric(), size=4)
readBin(zz, numeric(), size=4, endian="swap")
readBin(zz, complex(), 1)
readBin(zz, character(), 1)
z2 <- readBin(zz, character(), 1)
if(.Machine$sizeof.long == 8 || .Machine$sizeof.longlong == 8)
    readBin(zz, integer(), 10,  size = 8)
if((s <-.Machine$sizeof.longdouble) > 8)
    readBin(zz, numeric(), 10, size = s)
close(zz)
unlink("testbin")
stopifnot(z2 == z)

## signed vs unsigned ints[#签署对无符号整数]
zz <- file("testbin", "wb")
x <- as.integer(seq(0, 255, 32))
writeBin(x, zz, size=1)
writeBin(x, zz, size=1)
x <- as.integer(seq(0, 60000, 10000))
writeBin(x, zz, size=2)
writeBin(x, zz, size=2)
close(zz)
zz <- file("testbin", "rb")
readBin(zz, integer(), 8, size=1)
readBin(zz, integer(), 8, size=1, signed=FALSE)
readBin(zz, integer(), 7, size=2)
readBin(zz, integer(), 7, size=2, signed=FALSE)
close(zz)
unlink("testbin")

## use of raw[#使用的原料]
z <- writeBin(pi^{1:5}, raw(), size = 4)
readBin(z, numeric(), 5, size = 4)
z <- writeBin(c("a", "test", "of", "character"), raw())
readBin(z, character(), 4)

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


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

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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