0

Cannot find the answer how to load 7z file in R. I can't use this: s <- system("7z e -o <path> <archive>") because of error 127. Maybe that's because I'm on Windows? However, 7z opens when I click in TotalCommander.

I'm trying something like this:

con <- gzfile(path, 'r')
ff <- readLines(con, encoding = "UTF-8")
h <- fromJSON(ff)

I have Error:

Error: parse error: trailing garbage 7z¼¯' ãSp‹ Ë:ô–¦ÐÐY#4U¶å¿ç’ (right here) ------^

The encoding is totally not there, when I load this file uncompressed it's ok without specifying the encoding. Moreover it's 2x longer. I have thousands of 7z files need to read them one by one in a loop, read, analyze and get out. Could anyone give me some hints how to do it effectively?

When uncompressed it easily works using:

library(jsonlite)
f <- read_json(path, simplifyVector = T)

EDIT

There are many json files in one 7z file. The above error is probably caused by parser which reads raw data of whole file. I don't know how to link these files or specify the connection attributes.

Peter.k
  • 1,475
  • 23
  • 40
  • 1
    @576i's comment [here](http://stackoverflow.com/questions/16096192/how-to-programmatically-extract-or-unzip-a-7z-7-zip-file-with-r) indicates `s <- system("7z e -o ")` may solve the issue (i.e., without the space between -o and ``) . – Julia Wilkerson Mar 22 '17 at 00:41
  • Thanks, but I've seen it before and didn't work for me. – Peter.k Mar 22 '17 at 00:54
  • Do you have `7z.exe` in your windows `PATH` variable? If not you will need to specify the full path like this: `system("'C:\\Program Files\\7-Zip\\7z.exe' e -o ")` – AEF Mar 22 '17 at 07:18
  • On my system works: `>7z.exe e "c:/Users/cp/Downloads/CONVERTED/2181.7Z" *` command. Without `-o` flag. There must be something with the flags I'm doing wrong. In R still the same error status 127. – Peter.k Mar 22 '17 at 12:59

0 Answers0