awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
363 stars 79 forks source link

Encoding problem corrupted file #517

Open adamrobinson361 opened 3 years ago

adamrobinson361 commented 3 years ago

Expected Behaviour

I am using your package in a package of my own that reads a Power BI reports' underlying json file into R, extracts some data and makes an excel that can be used to support quality assurance of a report e.g. a dropdown for each visual (filters right, right narrative etc.)

In the development of reports a lot of users copy text from word with symbols in.

This loads into R fine but in its code representation when outputted in console. When used with saveData the existence of such text corrupts the file.

I'm looking to understand if anything can be done for these to be written correctly with a specific example below.

Steps to Reproduce the Problem

The following example is the down arrow symbol and if you run this locally you should see it error.

Ideally I'd like the symbol in the output excel. If not I'd like any sort of these characters to be removed (i.e. the ones that cause errors). I do want to keep other characters such as line breaks, *, &, etc.

Any help much appreciated.

x <- "\031"
wb <- openxlsx::createWorkbook()
openxlsx::addWorksheet(wb, "test")
openxlsx::writeData(wb, "test", tibble::data_frame(response = x))
openxlsx::saveWorkbook(wb, "test.xlsx", overwrite = TRUE)

sessionInfo()

R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5      crayon_1.3.4    lifecycle_0.2.0 magrittr_1.5   
 [5] zip_2.1.1       pillar_1.4.6    rlang_0.4.7     stringi_1.4.6  
 [9] renv_0.9.3      rstudioapi_0.11 vctrs_0.3.4     ellipsis_0.3.1 
[13] openxlsx_4.1.5  tools_3.6.2     glue_1.4.2      tinytex_0.25   
[17] xfun_0.16       compiler_3.6.2  pkgconfig_2.0.3 tibble_3.0.3  
ycphs commented 3 years ago

Could you please create this also at ycphs/openxlsx?

I am maintaining the active fork of the package.