Reputation: 419
I write a list of data.frames into an xlsx file with openxlsx. I do not like that the package changes the column names so that they contain the sheet name. Is there a way how to switch it off? I cannot find it.
library(openxlsx)
write.list <- function(data.list, filepath, digits=3, row.names=TRUE)
{
wb = createWorkbook()
for (i in 1:length(names(data.list))) {
idx = names(data.list)[i]
addWorksheet(wb, idx)
rounded = data.frame(lapply(data.list[idx], function(x)
{if(is.numeric(x)) round(x, digits) else x}))
writeData(wb, sheet=i, rounded, rowNames=row.names)
}
saveWorkbook(wb, filepath)
}
Upvotes: 1
Views: 764
Reputation: 3369
The problem is coming from where you are creating the rounded
object. You need to use a [[
instead of [
to get the list current list element. Changing the the rounded =
line to the following should correct this.
rounded = data.frame(lapply(data.list[[idx]], function(x)
Upvotes: 1