I'm new to R, and I'm trying to save data to an xlsx file. I'm using writexl (xlsx was causing trouble).
It seems that having strings and integers in my data frame causes problems when I try to use write_xlsx.
I've recreated the issue here:
library(writexl)
matrix <- matrix(1,2,2)
block <- cbind(list("ones","more ones"),matrix)
df <- data.frame(block)
data = list("sheet1"=df)
write_xlsx(data, path = "data.xlsx", col_names = FALSE, format_headers = FALSE)
The file data.xlsx correctly contains "sheet1", but it is blank. I would like
ones 1 1
more ones 1 1
Any way to get this output using write_xlsx?
I usually use openxlsx
package. Try and adapt the following code:
library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "Sheet1")
writeData(wb, "Sheet1", df, colNames = FALSE)
saveWorkbook(wb, "test.xlsx", overwrite = TRUE)