gzcon(base)
gzcon()所属R语言包:base
(De)compress I/O Through Connections
(德)压缩贯穿连接的I / O
译者:生物统计家园网 机器人LoveR
描述----------Description----------
gzcon provides a modified connection that wraps an existing connection, and decompresses reads or compresses writes through that connection. Standard gzip headers are assumed.
gzcon提供了修改后的连接,包装现有的连接,并解压读取或通过该连接压缩写道。假定标准gzip头。
用法----------Usage----------
gzcon(con, level = 6, allowNonCompressed = TRUE)
参数----------Arguments----------
参数:con
a connection.
一个连接。
参数:level
integer between 0 and 9, the compression level when writing.
压缩级别0到9之间的整数,当写。
参数:allowNonCompressed
logical. When reading, should non-compressed input be allowed?
逻辑。阅读时,应允许非压缩输入?
Details
详情----------Details----------
If con is open then the modified connection is opened. Closing the wrapper connection will also close the underlying connection.
con如果是开放的,然后修改连接被打开。关闭包装连接也将关闭底层连接。
Reading from a connection which does not supply a gzip magic header is equivalent to reading from the original connection if allowNonCompressed is true, otherwise an error.
从阅读,不提供一个gzip魔头连接是相当于阅读allowNonCompressed如果是真实的,否则一个错误,从原来的连接。
Compressed output will contain embedded NUL bytes, and so con is not permitted to be a textConnection opened with open="w". Use a writable rawConnection to compress data into a variable.
压缩输出将含有嵌入的NUL字节,con不允许是一个textConnectionopen="w"打开。使用一个可写的rawConnection压缩到一个变量的数据。
The original connection becomes unusable: any object pointing to it will now refer to the modified connection. For this reason, the new connection needs to be closed explicitly.
原来的连接变得不可用任何对象指向它现在将参照修改后的连接。出于这个原因,新的连接,需要明确地被关闭。
值----------Value----------
An object inheriting from class "connection". This is the same connection number as supplied, but with a modified internal structure. It has binary mode.
继承类"connection"对象。这是提供的,但修改后的内部结构相同的连接数目。它具有二进制模式。
参见----------See Also----------
gzfile
gzfile
举例----------Examples----------
## Uncompress a data file from a URL[#解压缩数据文件从一个URL]
z <- gzcon(url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz"))
# read.table can only read from a text-mode connection.[从文本模式连接,read.table可以只读。]
raw <- textConnection(readLines(z))
close(z)
dat <- read.table(raw)
close(raw)
dat[1:4, ]
## gzfile and gzcon can inter-work.[#gzfile和gzcon间工作。]
## Of course here one would use gzfile, but file() can be replaced by[#当然,在这里,人们会用gzfile,但可以替换文件()]
## any other connection generator.[#任何其他连接发电机。]
zz <- gzfile("ex.gz", "w")
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
readLines(zz <- gzcon(file("ex.gz", "rb")))
close(zz)
unlink("ex.gz")
zz <- gzcon(file("ex2.gz", "wb"))
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
readLines(zz <- gzfile("ex2.gz"))
close(zz)
unlink("ex2.gz")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|