全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3949 1
2012-02-01

以下内容来(译)自google R-help-archive小组,仅供参考。

各位,

   

我下载了一堆bz2文件(bz2 files),我想知道能不能用R软件将这些文件以批处理的方式解压,或者一次性全部解压?

   

我试过unz()函数,效果不是很好,提示我H:/Temp/65502805_532.pair.bz2.中有一个bz2文件。谁能给点建议啊?

   

非常感谢!

   

John


以下为R程序:


> setwd("H:\\Temp\\")

> getwd()

[1] "H:/Temp"

>fn<-list.files(pattern="bz2", full.names=TRUE)

> fn


[1] "./65502805_532.pair.bz2"

> unz(description=fn,filename="65502805_532.pair", open="r")


Error in unz(description = fn, filename ="65502805_532.pair", open = "r") :

cannot open the connection

In addition: Warning message:

In unz(description = fn, filename ="65502805_532.pair", open = "r") :

cannot open zip file './65502805_532.pair.bz2'

> sessionInfo()


R version 2.14.0(2011-10-31)

Platform: i386-pc-mingw32/i386 (32-bit)

locale:

[1] LC_COLLATE=English_UnitedStates.1252  LC_CTYPE=English_United

States.1252

[3] LC_MONETARY=English_United States.1252LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

attached base packages:

[1] stats     graphics grDevices utils     datasets  methods  base

other attached packages:

[1] pdInfoBuilder_1.18.0oligo_1.18.1         oligoClasses_1.16.0

affxparser_1.26.2    RSQLite_0.10.0

[6] DBI_0.2-5            Biobase_2.12.1

loaded via a namespace (and not attached):

[1] affyio_1.22.0         Biostrings_2.22.0     bit_1.1-8

ff_2.2-4              IRanges_1.12.1

[6] preprocessCore_1.16.0splines_2.14.0        tools_2.14.0

zlibbioc_1.0.0


答一:


我说的不一定对,但我觉得unz()函数只能处理zip文件,而不能处理bz2文件。

请参考R utils包中的bunzip2()函数。

Henrik



答二:


不妨用bzfile()函数代替unz() 函数,你将进入一个针对所有这些函数的帮助页面。

   

Luke Miller

   




【问答原文】


Ask


Hi,

   

I have downloaded abunch of bz2 files. I wonder if R will be able to unzip them in a batch mode oreven one at a time?

   

I was looking at the unzfunction. But it didn't work well. Say I have a bz2 file inH:/Temp/65502805_532.pair.bz2. Anyone has any suggestion?

   

thanks

   

John



> setwd("H:\\Temp\\")

> getwd()

[1] "H:/Temp"

>fn<-list.files(pattern="bz2", full.names=TRUE)

> fn


[1] "./65502805_532.pair.bz2"

> unz(description=fn,filename="65502805_532.pair", open="r")


Error in unz(description = fn, filename ="65502805_532.pair", open = "r") :

cannot open the connection

In addition: Warning message:

In unz(description = fn, filename ="65502805_532.pair", open = "r") :

cannot open zip file './65502805_532.pair.bz2'

> sessionInfo()


R version 2.14.0(2011-10-31)

Platform: i386-pc-mingw32/i386 (32-bit)

locale:

[1] LC_COLLATE=English_UnitedStates.1252  LC_CTYPE=English_United

States.1252

[3] LC_MONETARY=English_United States.1252LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

attached base packages:

[1] stats     graphics grDevices utils     datasets  methods  base

other attached packages:

[1] pdInfoBuilder_1.18.0oligo_1.18.1         oligoClasses_1.16.0

affxparser_1.26.2    RSQLite_0.10.0

[6] DBI_0.2-5            Biobase_2.12.1

loaded via a namespace (and not attached):

[1] affyio_1.22.0         Biostrings_2.22.0     bit_1.1-8

ff_2.2-4              IRanges_1.12.1

[6] preprocessCore_1.16.0splines_2.14.0        tools_2.14.0

zlibbioc_1.0.0


Answer


I may be wrong, but Idon't think unz() handles bz2 files - only zip files.

See bunzip2() of theR.utils package (which utilizes bzfile connections).

/Henrik


Answer


Try the bzfile() functioninstead of unz(). You'll find that you're taken to the same help page for bothof those functions.

?bzfile

   

Luke Miller



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-12-15 20:13:00
感谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群