【问题标题】:Error with tex2docx function from reports R package报告 R 包中的 tex2docx 函数出错
【发布时间】:2013-07-27 11:39:50
【问题描述】:

我正在尝试在 reports R 包中重现 tex2docx 函数的示例并收到以下错误。

DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex",
   package = "reports")
BIB <- system.file("extdata/docs/example.bib", package = "reports")
tex2docx(DOC, file.path(getwd(), "test.docx"), path = NULL, bib.loc = BIB)

错误信息

pandoc.exe: Error reading bibliography `C:/Users/Muhammad'
citeproc: the format of the bibliographic database could not be recognized
using the file extension.
docx file generated!
Warning message:
running command 'C:\Users\MUHAMM~1\AppData\Local\Pandoc\pandoc.exe -s C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/doc_library/apa6.qual_tex/doc.tex -o C:/Users/Muhammad Yaseen/Documents/test.docx --bibliography=C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/docs/example.bib' had status 23

我想知道如何让reports R 包中的tex2docx 函数正常工作。

【问题讨论】:

  • 我强烈怀疑您的文件路径中有空格问题。不过,除了在没有空格的文件路径中进行测试之外,不知道如何修复它。
  • 你说得对@BenBolker,我的文件路径有空格。任何解决方法。
  • 你也许可以破解包,让它在命令参数的相关组件周围加上引号。
  • 您可以 ping @tyler-rinker 以在 github.com/trinker/reports/blob/master/R/tex2docx.R 中添加 shQuote
  • 我实际上不确定如何执行shQuote,但如果这能解决问题,我将非常感谢有人提出请求。即使您更正了它,我也可以完成该文件中的其余功能。

标签: r report docx tex


【解决方案1】:

如上述 cmets 所述,错误是由传递的文件名/路径引起的,其中包括一些既未转义也未引用的空格。一种解决方法是在使用system 传递到命令行之前将所有文件路径和名称包装在shQuote 中。

代码:https://github.com/trinker/reports/pull/31


演示:

  1. 加载包

    library(reports)
    
  2. 创建一个名称中带有空格的虚拟目录,用于保存bib 文件

    dir.create('foo bar')
    file.copy(system.file("extdata/docs/example.bib", package = "reports"), 'foo bar/example.bib')
    
  3. 指定源和复制的bib文件:

    DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex", package = "reports")
    BIB <- 'foo bar/example.bib'
    
  4. 运行测试:

    tex2docx(DOC, file.path(getwd(), "test2.docx"), path = NULL, bib.loc = BIB)
    

免责声明:我试图测试这个拉取请求,但我无法设置一个包含所有需要的工具的环境,以便在 5 分钟内运行 R CMD check 和其他所有内容(抱歉,但是现在正在度假,午餐后只是享受午睡),所以请将此拉取请求视为“未经测试”——尽管它应该有效。

【讨论】:

  • 我合并了拉取请求。非常感谢。我查看了您使用shQuote 的方式和原因,我想我明白了。再次感谢。我构建了包并测试了示例,它可以工作(尽管路径中没有空格,所以 MYaseen208 必须进行测试)。开发版可以通过指令here下载。
  • 我将此添加到NEWS 文件中。我使用了 daroczig 的实际名称,但是,MYaseen208 我使用了您的 stackoverflow 句柄。如果您想使用您的姓名,请给我发送电子邮件。
  • 感谢@daroczig 和@Tyler Rinker 的帮助。您提供的代码在我的机器上仍然出现错误。错误消息是pandoc.exe: Error reading bibliography foo citeproc: the format of the bibliographic database could not be recognized using the file extension. docx file generated! Warning message: running command 'C:\Users\MUHAMM~1\AppData\Local\Pandoc\pandoc.exe -s C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/doc_library/apa6.qual_tex/doc.tex -o C:/Users/Muhammad Yaseen/Documents/test2.docx --bibliography=foo bar/example.bib' had status 23
  • 如果你运行reports:::wheresPandoc()会发生什么?
  • @TylerRinker:使用reports:::wheresPandoc() 给了我pandoc "C:\\Users\\MUHAMM~1\\AppData\\Local\\Pandoc\\pandoc.exe"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-06
  • 2015-06-09
  • 1970-01-01
  • 2020-02-17
相关资源
最近更新 更多