35

I wish to download and open the following tar.gz file in R:

http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz

Is there a command which can accomplish this?

Ben Bolker
  • 192,494
  • 24
  • 350
  • 426
Tal Galili
  • 23,433
  • 41
  • 122
  • 183

1 Answers1

60
fn <- "http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz"
download.file(fn,destfile="tmp.tar.gz")
untar("tmp.tar.gz",list=TRUE)  ## check contents
untar("tmp.tar.gz")
## or, if you just want to extract the target file:
untar("tmp.tar.gz",files="wp2011-survey/anon-data.csv")
X <- read.csv("wp2011-survey/anon-data.csv")

Offhand, I don't know of a way to reach into the tar file and read the appropriate csv file without unpacking it ...

Ben Bolker
  • 192,494
  • 24
  • 350
  • 426
  • is it also possible to untar only a specific file inside a tarball?? I think the `files` argument in `untar` does this but am unsure how ?? Help appreciated .. – Ashwin Dec 08 '14 at 10:27