[R] reading file in zip archive

Phil Spector spector at stat.berkeley.edu
Thu May 31 01:06:54 CEST 2012


Iain -
    Do you see the same behaviour if you use

z <- unz(pathToZip, 'x.txt')

instead of

z <- unz(pathToZip, 'x.txt','r')

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Wed, 30 May 2012, Iain Gallagher wrote:

> Hi Phil
> 
> Thanks, but this still doesn't work.
> 
> Here's a reproducible example (was wrapping my head around these functions before).
> 
> x <- as.data.frame(cbind(rep('a',5), rep('b',5)))
> y <- as.data.frame(cbind(rep('c',5), rep('d',5)))
> 
> write.table(x, 'x.txt', sep='\t', quote=FALSE)
> write.table(y, 'y.txt', sep='\t', quote=FALSE)
> 
> zip('test.zip', files = c('x.txt', 'y.txt'))
> 
> pathToZip <- paste(getwd(), '/test.zip', sep='')
> 
> z <- unz(pathToZip, 'x.txt', 'r')
> zT <- read.table(z, header=FALSE, sep='\t')
> 
> Error in read.table(z, header = FALSE, sep = "\t") :
>   seek not enabled for this connection
> 
> As I said in my previous email readLines fails as well. Rather strange really.
> 
> Anyway, as before any advice would be appreciated.
> 
> Best
> 
> Iain
> 
> _________________________________________________________________________________________________
> From: Phil Spector <spector at stat.berkeley.edu>
> To: Iain Gallagher <iaingallagher at btopenworld.com>
> Cc: r-help <r-help at r-project.org>
> Sent: Wednesday, 30 May 2012, 20:16
> Subject: Re: [R] reading file in zip archive
> 
> Iain -
>     Once you specify the file to unzip in the call to unz, there's no
> need to repeat the filename in read.table.  Try:
> 
> z <- unz(pathToZip, 'goCats.txt', 'r')
> zT <- read.table(z, header=TRUE, sep='\t')
> 
> (Although I can't reproduce the exact error which you saw.)
> 
>                     - Phil Spector
>                     Statistical Computing Facility
>                     Department of Statistics
>                     UC Berkeley
>                     spector at stat.berkeley.edu
> 
> 
> 
> On Wed, 30 May 2012, Iain Gallagher wrote:
> 
> > Hi List
> >
> > I have a series of zip archives each containing several files. One of these files is called
> goCats.txt and I would like to read it into R from the archive. It's a simple tab delimited text
> file.
> > pathToZip <-'/home/iain/Documents/Work/Results/bovineMacRNAData/deAnalysis/afInfection/commonNorm/twoHrs/af2
> hrs.zip'
> >
> > z <- unz(pathToZip, 'goCats.txt', 'r')
> > zT <- read.table(z, 'goCats.txt', header=T, sep='\t')
> >
> > Error in read.table(z, "goCats.txt", header = T, sep = "\t") :
> > ? seek not enabled for this connection
> >
> >
> > The same error arises with readLines.
> >
> > Can anyone advise?
> >
> > Best
> >
> > iain
> >
> >> sessionInfo()
> > R version 2.15.0 (2012-03-30)
> > Platform: x86_64-pc-linux-gnu (64-bit)
> >
> > locale:
> > ?[1] LC_CTYPE=en_GB.utf8?????? LC_NUMERIC=C????????????
> > ?[3] LC_TIME=en_GB.utf8??????? LC_COLLATE=en_GB.utf8???
> > ?[5] LC_MONETARY=en_GB.utf8??? LC_MESSAGES=en_GB.utf8??
> > ?[7] LC_PAPER=C??????????????? LC_NAME=C???????????????
> > ?[9] LC_ADDRESS=C????????????? LC_TELEPHONE=C??????????
> > [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C?????
> >
> > attached base packages:
> > [1] stats???? graphics? grDevices utils???? datasets? methods?? base????
> >
> > loaded via a namespace (and not attached):
> > [1] tools_2.15.0
> >     [[alternative HTML version deleted]]
> >
> >
> 
> 
> 
>


More information about the R-help mailing list