Download, unzip, and load Excel file in R using tempfiles only -


i trying , failing write process download .zip archive, extract particular excel file archive, , load excel file r workspace without ever writing of files (the .zip or .xls) hard drive.

i have written version of process works zipped .csvs, doesn't work .xls. here's how version goes, using 1 of urls i'm targeting in current project , using readworksheetfromfile() instead of read.csv() @ appropriate moment:

library(xlconnect) waed.old.link <- "http://eventdata.parusanalytics.com/data.dir/pitf.world.19950101-20121231.xls.zip" waed.old.file <- "pitf.world.19950101-20121231.xls" tmp <- tempfile() download.file(waed.old.link, tmp) tmp2 <- tempfile() tmp2 <- unz(tmp, waed.old.file) waed.old <- readworksheetfromfile(tmp2, sheet = 1, startrow = 3, startcol = 1, endcol = 73) unlink(tmp) unlink(tmp2) 

and here's pops after line 8, 1 tries ingest spreadsheet waed.old:

error in path.expand(filename) : invalid 'path' argument 

i tried read_excel() @ step , got same result:

> waed.old <- read_excel(tmp2, skip = 2) error in file.exists(path) : invalid 'file' argument 

i gather has pointing readworksheetfromfile() @ connection rather file, i'm not sure that's right, , don't know how fix if is. searched stackoverflow , web answer couldn't find 1 right on point. i'd appreciate help.

as say, because unz returns connection object file within zip (but not explicitly unzip file), while readworksheetfromfile expects path file.

use unzip explicitly unzip file.

tmp2 <- unzip(zipfile=tmp, files = waed.old.file, exdir=tempdir()) # readworksheetfromfile(tmp2, ...) 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -