When I call xlsx::write.xlsx()
on a tibble with 2+ rows it crashes:
df <- structure(list(`region name` = c("Reg 1", "Reg 2"),
`value` = c(1.38755717255717, 1.26297588082289)),
row.names = c(NA, -2L),
class = c("tbl_df", "tbl", "data.frame"))
xlsx::write.xlsx(df, file = "myfilename.xlsx", row.names = F, showNA = F)
and returns:
Error in if (is.na(value)) { : the condition has length > 1
1st option
If I call the same script setting default row.names = T
it executes properly but adds an unneeded column with row number.
xlsx::write.xlsx(df, file = "myfilename.xlsx",
row.names = T, # I can skip the parameter
showNA = F)
2nd option
If I pick only one row from the tibble the script executes entirely as expected.
xlsx::write.xlsx(df[1, ], file = file = "myfilename.xlsx", row.names = F, showNA = F)
3rd option
If I convert data to data frame it executes without an error but modifies column names due to data.frame restrictions:
xlsx::write.xlsx(data.frame(df), file = paste0(pthout, "myfile.xlsx"), row.names = F, showNA = F)
Is it a bug in xlsx::write.xlsx()
or I can do something with it?