I am a novice in R. I have a zip file with the name "test_file.zip" which contains 5 different CSV files. The names are file1.csv, file2.csv, file3.csv, file4.csv and file5.csv. This zip file is created by some other program and I do not have much details on the compression technology used. I am trying to read the zip file directly using the below code.
file_name = read.csv(file = unzip("test_file.zip"), header = TRUE)
The above code works perfectly if the zip file has only one csv file. It does not work if there are multiple zip files. I get the below error message.
Error in file(file, "rt") : invalid 'description' argument
I tried using the unzip
function as shown below. I am able to get the names of the files within the zip file but I am unable to read them for some reason.
file_list <- unzip("test_file.zip", list = TRUE)
file_list$name
[1] "file1.csv"
[2] "file2.csv"
[3] "file3.csv""
[4] "file4.csv"
[5] "file5.csv"
read_file1 <- read.csv(file = unzip(file_list$name[1]), header = TRUE)
Error in file(file, "rt") : invalid 'description' argument
In addition: Warning message:
In unzip(file_list$name[1]) : error 1 in extracting from zip file
What am i doing wrong? How can I read multiple csv files from a single zip file from R? They all should be created as separate data frames as I have to perform other tasks on each of the files. Is this possible in R? Any help or guidance on how I should proceed would really be appreciated.