Ilja
Ilja

Reputation: 631

R - zip file extract

It's very silly not to find the solution here, so I write the question.I'm sorry upfront if its too basic.

I have a zip file in directory

dir <- "C:/Users/...

setwd(dir

to_open <- list.files(dir,".zip")

to_open

[1] "getdata-projectfiles-UCI HAR Dataset.zip"

And now I tried some 100 functions just to see the zipped directory. There are some 3 files with some 5 csv/txt files each.

How can I call them from inside R?

So far I only succeeded with unzip(to_open) which leaves a mess behind with more files in the directory and less reproducible code.

Please help! Thanks

Upvotes: 0

Views: 2265

Answers (1)

Thierry
Thierry

Reputation: 18487

You could unzip the files one by one into another directory and clean up afterward

td <- tempdir()
unzip(file_to_unzip, ex = td)
# do something with the files
file.remove(list.files(td, full.names = TRUE))

Upvotes: 1

Related Questions