I'm looking to download a gzipped csv and load it as an R object without saving it first to disk. I can do this with zipped files but can't seem to get it to work with gzfile
or gzcon
.
Example:
grabRemote <- function(url) {
temp <- tempfile()
download.file(url, temp)
aap.file <- read.csv(gzfile(temp), as.is = TRUE)
unlink(temp)
return(aap.file)
}
grabRemote("http://dumps.wikimedia.org/other/articlefeedback/aa_combined-20110321.csv.gz")
That downloads a (small) gz compressed file containing Wikipedia article feedback data (not important, but just to indicate it isn't giant or nefarious).
The code I have works fine but I feel like I'm missing something very obvious by resorting to creating and destroying a temporary file.