3

Possible Duplicate:
unzip a tar.gz file?

I have a tar.gz file which contains a set of CSV files in it. How do I read only one file into R data frame?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132

1 Answers1

5

If you know the filename of the file in the archive you want then you can specify that it be extracted and then read as per usual. E.g.

untar("foo.tar.gz", files = "foo2.csv")

will extract the file foo2.csv from the archive foo.tar.gz into the current working/local directory. You can then load that CSV in the usual way

read.csv("foo2.csv")

If you don't know the filenames, list them first:

> untar("foo.tar.gz", list = TRUE)
[1] "foo.csv"  "foo2.csv"

then extract the one you want.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453