Closed MaxSerna closed 3 years ago
Note:
I can open the created chart by calling print()
with the preview
argument, and check that the word "Ópera" is there. I just cannot export it to Word.
print(my_barchart, preview = TRUE)
Same issue applies for other non-ASCII characters such as the nordic letters æøåÆØÅ.
My dirty post hoc fix solution to this problem in case it helps anyone.
print2.rdocx <- function(x, target=file.path(getwd(), "tmp.docx")) {
# Unzip everything in temp, recode chart files to UTF-8 and return
current_wd <- getwd()
dir.create(tmp_zip_dir <- tempfile())
tmp_zip <- tempfile(fileext = ".docx")
print(x, target = tmp_zip)
out <- utils::unzip(zipfile = tmp_zip, exdir = tmp_zip_dir)
out <- grep(pattern = "charts\\/.*\\.xml$", x = out, value = TRUE)
lapply(out, function(xml_file) {
xml_content <- readr::read_file(xml_file)
xml_content <- iconv(x = xml_content, from = "latin1", to = "UTF-8")
readr::write_file(x = xml_content, file = xml_file, append = FALSE)
})
#### Replace with officer::pack_folder(folder=tmp_zip_dir, target=file.path(path, paste0(file_prefix, ".docx")))
setwd(tmp_zip_dir)
out <- list.files(path = tmp_zip_dir, all.files = TRUE, recursive = TRUE, include.dirs = FALSE)
utils::zip(files=out, zipfile = tmp_zip)
setwd(current_wd)
file.copy(from = tmp_zip, to = target, overwrite = TRUE, copy.date = TRUE)
target
}
Created on 2021-04-09 by the reprex package (v2.0.0)
I am working on the package - there are things to fix and improve first. I will then fix that issue.
This is fixed now. Thanks for reporting this issue
I´m having an issue when trying to create bar charts where axis labels have accent marks. I first had the same issue when writing paragraphs with accented words, but I managed to solve it by just calling the
enc2utf8()
function, as is shown in the first exampleenc2utf8('Téstíng testing aé')
.This works fine.
Unfortunately that doesn´t work with chart axis labels. In the following example, I added "Ópera" instead of "Opera" in the data, using
enc2utf8()
again. (Does not work withoutenc2utf8()
either).Then I run the same code. I just omitted tha paragraph and changed the
data
argument in thems_barchart()
function.But I get this error when I try to open the file.
"We're sorry. We can't open XXX.docx because we found a problem with its contents", and no details available.
This is my session info
I did check the issues sections to find a solution, which I did for
body_add_par()
, but I wasn´t able to find anything regarding charts. Thanks in advance!