Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write.xlsx error in Error in .jnew and j.check in R

Tags:

dataframe

r

excel

I was trying to write a dataframe with 523370 rows and 3 columns using write.xlsx

write.xlsx(x = dataframe, file = "dataframe.xlsx",
+ sheetName = "dataframe1", row.names = FALSE)

but I get this error :

    Error in .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook") : 
  Java Exception <no description because toString() failed>.jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")<S4 object of class "jobjRef">

and I check these question :

  • How to clear memory used by rJava? : xlcFreeMemory() and then try to write the file but after a rather long time I get the same error
  • R writing excel file with XLSX package taking a long time and error : write.xlsx2() gave me the same error,after running this one : options(java.parameters = "-Xmx1024m")and rebooting the system

But that changed the error changed to:

Error in .jcheck(silent = FALSE) :Java Exception <no description because toString() failed>.jcall(row[[ir]], "Lorg/apache/poi/ss/usermodel/Cell;", "createCell", as.integer(colIndex[ic] - 1))<S4 object of class "jobjRef">
like image 473
academic.user Avatar asked Jan 03 '15 14:01

academic.user


People also ask

What package is xlsx in R?

The xlsx package gives programatic control of Excel files using R. A high level API allows the user to read a sheet of an xlsx document into a data. frame and write a data.


2 Answers

I had the same problem and restarting R did the trick.

If you're using RStudio the keystroke shortcut for restarting R is Ctrl + Shift + F10 (PC) or Command + Shift + F10 (Mac).

like image 124
Tomás Barcellos Avatar answered Oct 04 '22 08:10

Tomás Barcellos


Try to use write.xlsx from openxlsx package that does not use java.

openxlsx::write.xlsx(x = dataframe, file = "dataframe.xlsx")
like image 38
Scipione Sarlo Avatar answered Oct 04 '22 10:10

Scipione Sarlo