uncompress(uncompress)
uncompress()所属R语言包:uncompress
Uncompress .Z file data
Z文件解压缩。数据
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Uncompresses data compressed with the "compress" utility. Data pass in and returned are both raw binary strings. Invalid compressed data results in an error being returned.
解压缩数据压缩的“压缩”程序。数据传递和返回都是原始的二进制字符串。无效的压缩数据会导致错误被退回。
用法----------Usage----------
uncompress(data)
参数----------Arguments----------
参数:data
The raw binary data to decompress.</table>
原始二进制数据进行解压缩。</ TABLE>
实例----------Examples----------
library("uncompress")
## Not run: [#不运行:]
## Example 1 - extracting text data from a .Z file.[#示例1 - 从Z文件中提取文本数据。]
handle <- file("file.Z", "rb")
# The size here is arbitrary, it should be large enough for most files,[这里的大小是任意的,它应该足够大,对于大多数文件,]
# adjust as necessary.[调整是必要的。]
data <- readBin(handle, "raw", 99999999)
close(handle)
uncomp_data <- uncompress(data)
# At this point you might want to check if uncomp_data is NULL in case the[在这一点上,你可能要检查的情况下,如果uncomp_data是NULL]
# file is corrupt.[文件已损坏。]
# This is assuming it's Unix-style text (i.e. \n separates lines).[这是假设它的Unix风格的文本(即\ n分隔行)。]
# If it's Windows-style text you may need to use "\r\n".[如果是Windows风格的文字,你可能需要使用“\ r \ n”。]
lines <- strsplit(rawToChar(uncomp_data), "\n")
print(lines)
## Example 2 - extracting text data from a .Z file at an HTTP host.[#2 - 在一个HTTP主机从Z文件中提取文本数据。]
handle <- url("http://host/path/file.Z", "rb")
# The size here is arbitrary, it should be large enough for most files,[这里的大小是任意的,它应该足够大,对于大多数文件,]
# adjust as necessary.[调整是必要的。]
data <- readBin(handle, "raw", 99999999)
close(handle)
uncomp_data <- uncompress(data)
# At this point you might want to check if uncomp_data is NULL in case the[在这一点上,你可能要检查的情况下,如果uncomp_data是NULL]
# file is corrupt.[文件已损坏。]
# This is assuming it's Unix-style text (i.e. \n separates lines).[这是假设它的Unix风格的文本(即\ n分隔行)。]
# If it's Windows-style text you may need to use "\r\n".[如果是Windows风格的文字,你可能需要使用“\ r \ n”。]
lines <- strsplit(rawToChar(uncomp_data), "\n")
print(lines)
## Example 3 - downloading a .Z file, then uncompressing it.[#3 - 。Z文件下载,然后解压缩。]
# Mode is important, in Windows if you don't use binary mode the compressed[模式是很重要的,在Windows中,如果你没有使用二进制模式下压缩]
# data will be corrupted.[数据将被破坏。]
download.file("http://host/path/file.Z", "file.Z", mode="wb")
handle <- file("file.Z", "rb")
# The size here is arbitrary, it should be large enough for most files,[这里的大小是任意的,它应该足够大,对于大多数文件,]
# adjust as necessary.[调整是必要的。]
data <- readBin(handle, "raw", 99999999)
close(handle)
uncomp_data <- uncompress(data)
# At this point you might want to check if uncomp_data is NULL in case the[在这一点上,你可能要检查的情况下,如果uncomp_data是NULL]
# file is corrupt.[文件已损坏。]
# This is assuming it's Unix-style text (i.e. \n separates lines).[这是假设它的Unix风格的文本(即\ n分隔行)。]
# If it's Windows-style text you may need to use "\r\n".[如果是Windows风格的文字,你可能需要使用“\ r \ n”。]
lines <- strsplit(rawToChar(uncomp_data), "\n")
print(lines)
## Example 4 - downloading a .Z file, writing the uncompressed data to a[例4 - 下载。Z文件,未压缩数据写入到]
## local file.[#本地文件。]
handle <- url("http://host/path/file.Z", "rb")
# The size here is arbitrary, it should be large enough for most files,[这里的大小是任意的,它应该足够大,对于大多数文件,]
# adjust as necessary.[调整是必要的。]
data <- readBin(handle, "raw", 99999999)
close(handle)
uncomp_data <- uncompress(data)
handle <- file("file", "wb")
writeBin(uncomp_data, handle)
close(handle)
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|