我有一堆现有的RTF表,并希望在使用R包“ReporteRs”时将它们添加到.docx文件中 . 但它还不支持外部RTF表 . 所以我试图将文件路径插入.docx文件并切换链接以获取表 . 为此,我需要在文件路径周围添加一对大括号“{}” . 但是简单地在文件路径周围添加符号“{}”将无法完成工作,因为大括号将被转换为单词中的某些RTF代码,而“{}”的后台RTF代码实际上非常复杂 . 现在,我的问题是:

(1)如何在rtf文件路径周围添加可解析的大括号“{}”,以便我可以切换链接 . 我试图使用我发现的替换大括号的rtf代码,但它不能被Microsoft WORD遵从大括号 . 我发现的rtf代码是这样的:

{\ field {* \ fldinst {\ rtlch \ fcs1 \ af31503 \ ltrch \ fcs0 \ insrsid8593807 \ hich \ af31502 \ dbch \ af31501 \ loch \ f31502 \ hich \ af31502 \ dbch \ af31501 \ loch \ f31502 INCLUDETEXT“\\我的文件pth \ d0blchar.rtf“\ c MSRTF \ hich \ af31502 \ dbch \ af31501 \ loch \ f31502}}

我希望WORD能解决这个问题:{INCLUDETEXT“\ my file pth \ d0blchar.rtf”\ c MSRTF}

但在我看来,WORD无法进行编译 .

(2)如果(1)不可行,在R创建WORD文件时是否还有其他R包可以包含到WORD文件的RTF表?

附上我的示例代码:

library(ReporteRs)
path<-'\\\\\\\\mypath\\data\\table1.rtf' #path for the related TLFS
report<-docx()                           #initialize the docx object

text1<-"{\\field{\\*\\fldinst {\\rtlch\\fcs1 \\af31503 \\ltrch\\fcs0 \\insrsid8593807 \\hich\\af31502\\dbch\\af31501\\loch\\f31502  \\hich\\af31502\\dbch\\af31501\\loch\\f31502  "
text2<-"\\hich\\af31502\\dbch\\af31501\\loch\\f31502  }}"

fileAdd<-paste0(text1,"INCLUDETEXT \"", path, "\" \\c MSRTF", text2)
report<-addParagraph(report,fileAdd) #add rtf tables
writeDoc(report, file="Report.docx") #output the docx file

============================================

非常感谢!