Using the writexl
package I can write a data.frame into an xlsx file, while keeping special characters in the xlsx file, because the data is saved in UTF-8 encoding (on Mac). This works when I run my R script from the R console.
However, when I schedule a cronjob to run the exact same R-script, the xlsx file is saved using a different encoding so that special characters are not shown. Is there a way to change the encoding in a cronjob.
I could not find any documentation on how to add an argument related to the encoding using the cronR
package (https://github.com/bnosac/cronR) or writexl
package nor change the encoding from within the R script using any the following lines:
options(encoding = "UTF-8")
or by changing the encoding of the character columns into UTF-8:
data_table <- data_table %>% mutate_if(is.character,
list(~enc2utf8(.)))
before writing the dataframe to xlsx
writexl::write_xlsx(data_table, "filename.xlsx")
Does anyone know how the encoding can be changed to UTF-8 while running a cronjob so that special characters are visible in the saved xlsx file?