ycphs / openxlsx

openxlsx - a fast way to read and write complex xslx files
https://ycphs.github.io/openxlsx/
Other
220 stars 73 forks source link

Coerce matrix to data.frame in writexlsx.R #449

Closed grantbrown closed 5 months ago

grantbrown commented 9 months ago

write.xlsx produces empty or incorrectly formatted files if the argument is a matrix instead of a data frame. This is one potential workaround for a (potentially) common mistake in usage. An alternative approach would be to more explicitly enforce the type of the x argument.

Simple example which will silently fail without something like the embedded commit:

library(openxlsx)
X <- matrix(rnorm(100), ncol = 10)
write.xlsx(X, file = "tmp.xlsx", replace = TRUE)