'"replacement has length zero" when exporting data frame to xlsx in R

I am trying to export a dataframe with library(openxlsx) and

openxlsx::write.xlsx(as.data.frame(df), file = "df.xlsx", colNames = TRUE, rowNames = FALSE, append = FALSE)

but I get the following error:

Error in x[is.na(x)] <- na.string : replacement has length zero



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source