3

I am taking the R programming class from Cousera, and while I was practising how to read in xlsx files using read.xlsx, I encountered the following error message:

dat<- read.xlsx(file="./data/nga.xlsx", sheetIndex=1)

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.util.zip.ZipException: oversubscribed literal/length tree

R version 3.2.1, R studio version 3.2.1, platform windows7 64bit. Can anyone give a hint what this message means and how to work around it?

Thanks, Gezimao

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Gezimao
  • 47
  • 1
  • 5
  • Your RStudio version sounds wrong, for example mine is `Version 0.99.441`; you can get this by Help->About RStudio – MichaelChirico Jul 12 '15 at 00:10
  • About your issue, two things to try: First run `gc()` and try again; second, try using `read.xlsx2` instead of `read.xlsx` and see what happens. If that doesn't work, make sure that the file path is correct, for example by using `list.files("./data/")` and make sure `nga.xlsx` is there. – MichaelChirico Jul 12 '15 at 00:11
  • From these ([1](http://stackoverflow.com/questions/3183979/java-util-zip-zipexception-incomplete-literal-length-tree),[2](http://stackoverflow.com/questions/3049448/java-util-zip-zipexception-oversubscribed-dynamic-bit-lengths-tree),[3](http://stackoverflow.com/questions/3377761/oversubscribed-literal-length-tree-error-while-creating-database)) questions about what the underlying `Java` is doing, it seems there's a problem with a `zip` file somehow, but I don't know why any `zip` files are getting involved. – MichaelChirico Jul 12 '15 at 00:14
  • If nothing works, you can try `readxl`, `openxlsx`, or any of these [Read Excel files from R](http://www.r-bloggers.com/read-excel-files-from-r/) – Pierre L Jul 12 '15 at 00:15
  • 1
    Why? `.xlsx` format is a zipped version of a variant XML. If you unzip one you get several folders that hold different components in .xml files – IRTFM Jul 12 '15 at 00:30
  • @BondedDust good to know, thanks. In that case, making sure you can actually open the file in Excel (or Libre/Open Office, etc.) without any errors is another step in debugging. – MichaelChirico Jul 12 '15 at 18:05

4 Answers4

2

The file you have downloaded was corrupted, so download again that file using the parameter 'mode="wb"'.

Jack
  • 165
  • 2
  • 10
1

try this package https://github.com/hadley/readxl

read_excel("my-new-spreadsheet.xlsx")
Ajay Ohri
  • 3,382
  • 3
  • 30
  • 60
0

I had the same problem. The .xlsx file may be 'read only'. Try 'Save As' to a new file from Excel and try read.xlsx again.

0

Download and install this java:http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html

then run your code and it should work. If it does check best answer :)

Seekheart
  • 1,135
  • 7
  • 8