I can't understand the downvote. I thought some people would know how to do it using just an option, without the need of manually tansforming every NA.
As I think it could be important and useful for other users I've also asked on openxlsx's github development page and they replied:
https://github.com/awalker89/openxlsx/issues/108#issuecomment-125142950
In case anybody is interested, if you update to the dev version with
devtools::install_github("awalker89/openxlsx")
you will get support for this feature.
the default behaviour now is converting NAs to blanks
And if we want to have #N/A we must use the option keepNA = TRUE
the option keepNA = TRUE keeps the #N/A
require('openxlsx')
df <- head(iris)
df[2,3] <- NA
df[2,5] <- NA
df[3,5] <- NaN
openXL(write.xlsx(df, file = tempdir()))
require('openxlsx')
df <- head(iris)
df[2,3] <- NA
df[2,5] <- NA
df[3,5] <- NaN
openXL(write.xlsx(df, file = tempdir(), keepNA = TRUE))
df[] <- lapply(df, function(x) {x[is.na(x)] <- "";x})
– Bascule