使用openxlsx软件包将xlsx写入包含utf-8字符的大型数据框

我试图写一个相当大的数据框(超过200列和超过6000行),其中包括希伯来字符超过使用openxlsx包shiny。
由于某种原因,当我下载文件时,我得到一个腐败的Excel文件,当试图打开它,我得到一个

excel发现不可读的内容是否要恢复此工作簿的内容

接着:

excel能够通过修复或删除不可读的内容来打开文件

一旦我打开文件,所有的希伯来字符都不见了!
试图重现这个问题,我发现,如果我尝试写一个较小的数据框为例[100:100]它的作品是希伯来文在那里,但是一旦我使我的数据框变大,它不起作用。
这里是我在下面的testing代码中使用的文件的链接
这里是我使用的代码:
server.R

library(shiny) library(openxlsx) shinyServer(function(input, output) { datasetInput <- reactive({ file_1 <- read.csv("../file1.txt", header=T, stringsAsFactors =F) file1<-file_1[1:200,1:200] ##if i place here [100:100] it works fine! return(file1) }) output$table <- renderTable({ datasetInput() }) output$downloadData <- downloadHandler( filename = function() { paste("download", "xlsx", sep='.') }, content = function(file){ fname <- paste(file,"xlsx",sep=".") wb <- createWorkbook() print(class(datasetInput())) addWorksheet(wb = wb, sheetName = "Sheet 1", gridLines = FALSE) writeDataTable(wb = wb, sheet = 1, x = datasetInput()) saveWorkbook(wb, file, overwrite = TRUE) } ) }) 

ui.R

  shinyUI(pageWithSidebar( headerPanel('Download Example'), sidebarPanel( downloadButton('downloadData', 'Download') ), mainPanel( tableOutput('table') ) )) 

感谢这个软件包Alexander Walker的创build者,问题解决了:
看来这个问题是由于string“\ b”中的转义字符引起的

 > x <- read.csv("file1.txt") > x[150,44] [1] ÷øéîéðåìåâéä áäúîçåú áîãò ôåøðæé - îåñîê \b 

解决方法是:

 x <- read.csv("file1.txt", stringsAsFactors = FALSE) wb <- createWorkbook() addWorksheet(wb, "Sheet 1") 

(is_character_col){x [[i]] < – gsub(“\ b”,“”,x [[i]]中的is_character_col < – 其中(sapply(x,class)%in%“character” fixed = TRUE)}

writeDataTable(wb,1,x)saveWorkbook(wb,“hopefully_fixed.xlsx”)