-1

I am using R.2.15.2 on Windows 7 and I cannot unzip a .gz file stored on the network. I am also using gnuwin32 (if it helps)

The file is seen, so the location is ok

system("ls")
file1.bla.gz
file2.bla.gz
file3.bla.gz
...

R) unzip("./file1.bla.gz")
Message d'avis :
In unzip("./file1.bla.gz") :
erreur 1 lors de l'extraction d'un fichier zip

R) untar("./file1.bla.gz")
/usr/bin/tar: This does not look like a tar archive
/usr/bin/tar: Skipping to next header

Using the function unzip is nor working, it looks like it is only dealing with .zip files. Not sure if the problem lies in the network or if I call It wrongly...

How can I extract this file ?

EDIT: The following worked

system(" \"C:\\Program Files\\7-Zip\\7z.exe\" e -y file1.bla.gz")

And gunzip from R.utils is even better thanks to @Paul Hiemstra

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
statquant
  • 13,672
  • 21
  • 91
  • 162

1 Answers1

2

You can use gzfile to access the content of a gzip compressed file, for example:

read.table(gzfile("/tmp/foo.csv.gz")) 

where foo.csv.gz is a gzip compressed csv file. I got this form @DirkEddelbuettel's answer in this post.

If your goal is to extract the file, you can use the gunzip function from the R.utils package. See this R-help post.

Community
  • 1
  • 1
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
  • Well I thought it worked, but not, so this is for `.tar` archives not `.gz` – statquant Apr 17 '13 at 14:25
  • `tar` also supports extracting `gzip` archives as they are often used in tandem. `tar` to create a single file which contains all the files, and `gzip` to add compression. – Paul Hiemstra Apr 17 '13 at 14:31
  • http://stackoverflow.com/questions/5764499/decompress-gz-file-using-r says it should work. – Paul Hiemstra Apr 17 '13 at 14:33
  • I don't think so, the link you are refering to call for `untar` if `tar.gz` which is not my case. I edited to show you the failure message – statquant Apr 17 '13 at 14:38
  • You can use `gzfile` to access a gzip compressed file, see my updated answer. – Paul Hiemstra Apr 17 '13 at 14:41
  • Paul, I would do this if the goal was to load the data into `R`, but the only thing I want is to unzip the file plain and simple... Anyway since version 2.10 I think, you can read a `csv.gz` file directly anyway with `read.table` see http://blog.revolutionanalytics.com/2009/12/r-tip-save-time-and-space-by-compressing-data-files.html – statquant Apr 17 '13 at 14:45
  • You can use `gunzip` from the `R.utils` package. – Paul Hiemstra Apr 17 '13 at 14:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28382/discussion-between-paul-hiemstra-and-statquant) – Paul Hiemstra Apr 17 '13 at 14:55