Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R xlsx addDataFrame produces Error in sheet$getWorkbook : $ operator is invalid for atomic vectors

I just installed the xlsx package and the requisite 64 bit Java for javaR behind it. I am trying to start with an incredibly simple operation: put an existing data frame into a spreadsheet. Every time I try to actually add the data frame to the worksheet, I get the error above.

TimingReport <- createWorkbook() ##brand new workbook--seems fine
createSheet(TimingReport,"Year2015") ##brand new sheet in workbook--seems fine
addDataFrame(DataFromEarlier, "Year2015") ##add data frame--throws error

I checked the type on DataFromEarlier, and it is an actual data frame, not a matrix. But just in case something was wrong with it, I also tried making a clean demo data table.

data <- data.frame(mon=c(1,2,3), day=c("m","w","f")) 
addDataFrame(data, "Year2015")

Throws the same dang error! Any ideas as to what the underlying problem is and how to fix it?

like image 907
NotMyJob Avatar asked Feb 17 '15 23:02

NotMyJob


1 Answers

Provide addDataFrame function a sheet object - not just a sheet name:

TimingReport <- createWorkbook() ##brand new workbook--seems fine
sheet <- createSheet(TimingReport,"Year2015") ##brand new sheet in workbook--seems fine
addDataFrame(DataFromEarlier, sheet) ##add data frame--throws error
like image 70
bergant Avatar answered Nov 05 '22 17:11

bergant