【发布时间】:2017-02-06 13:07:09
【问题描述】:
我正在研究使用 R 将文本文件转换为 pdf 的功能。
我正在使用 rmarkdown。
SO上已经提供了一个脚本来做,如下:
require(rmarkdown)
my_text <- readLines("YOUR PATH")
cat(my_text, sep=" \n", file = "my_text.Rmd")
render("my_text.Rmd", pdf_document())
file.remove("my_text.Rmd") #cleanup
效果很好。
我想把它写成一个函数。
我的功能如下:
convertTOtext<-function(.txt){
require(rmarkdown)
my_text <- readLines(.txt)
cat(my_text, sep=" \n", file = "Report.Rmd")
render("Report.Rmd", pdf_document())
#file.remove("my_text.Rmd") #cleanup
}
但是,当我将函数作为 convertTOtext(test.txt) [我与文本文件在同一目录中] 运行时,我收到以下错误:
processing file: Report.Rmd
output file: Report.knit.md
! Undefined control sequence.
l.144 ``C:\Users
pandoc.exe: Error producing PDF
Show Traceback
Rerun with Debug
Error: pandoc document conversion failed with error 43 In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS Report.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output Report.pdf --template "C:\Users\user\Documents\R\win-library\3.3\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
我做错了什么?
有人可以帮忙吗?
问候。
【问题讨论】:
标签: r pdf r-markdown pandoc