I’m trying to export a data frame to .xlsx file using the write.xlsx function in the openxlsx package. I keep receiving the error below and not sure how to get around it. Do you know what the issue is?
Since I can't see the dataset, I can only make an educated guess, but I think the important part of the error is: input string 3478246 is invalid UTF -8
This means there are unsupported characters in the text that cannot be handled by the file format. It seems that the path sting is all right (although some systems have issues with spaces in path names) so I guess one of the columns in the dataframe qry_Claims_Transactions contains unsupported characters. Could this be the case? If so, you should remove the characters, replace them or save in a format that can handle them.
The iconv function can be used to convert character columns to valid UTF-8. For example (adapted from here):
# Example data with wrong encoding
x <- "fa\xE7ile"
Encoding(x) <- "latin1"
# Check encoding
Encoding(x)
# Convert to valid UTF-8
xx <- iconv(x, from=Encoding(x), to="UTF-8", sub='')
Encoding(xx)