Error in printing data.frame in excel using XLSX package in R Error in printing data.frame in excel using XLSX package in R r r

Error in printing data.frame in excel using XLSX package in R


Still no reproducible example, but from your class(q1) it appears that q1 is a tbl_df (the sort of dataframe that the dplyr package produces) whereas write.xlsx expects a data.frame.

Try giving write.xlsx a plain data.frame as it expects. e.g.

write.xlsx(as.data.frame(q1), ...)

Here's a reproducible example (i.e. you could copy-paste it into your R session to reproduce the bug + fix).

library(dplyr)iris2 <- tbl_df(iris)class(iris2) # like yours# [1] "tbl_df"     "tbl"        "data.frame" # Now let's try to write to XLSX using command as mentioned in your commentslibrary(xlsx)write.xlsx(iris2, file='test.xlsx', sheetName="Sheet1", col.names=TRUE, row.names=FALSE, append=TRUE)# Error in .jcall(cell, "V", "setCellValue", value) : #   method setCellValue with signature ([D)V not found# In addition: Warning message:# In if (is.na(value)) { :#  the condition has length > 1 and only the first element will be used# ^--- we can reproduce your error. This is the point of a reproducible example, so we can see if our fixes work for you.

Now let's try fix it by making sure that write.xlsx gets a data.frame, not a tbl_df!

write.xlsx(as.data.frame(iris2), file='test.xlsx', sheetName="Sheet1", col.names=TRUE, row.names=FALSE, append=TRUE)# huzzah!


I find this happens when grouping variables with dplyr. If you end a chain with %>% ungroup () it appears to resolve


It seems that there is a bug with the Date/Time format of the first column (Timestamp). If you convert the first column to character, it should work. So, you may change your first column to

q1[,1] <- as.character(q1[,1])

and try again...