2017-04-07 129 views
3

我有R软件包,它的一个函数 - 生成报告。 在安装/降价我有一个模板rep.rmd 在包装功能ProduceReport()我有这样的代码:当output_file路径是绝对路径时,rmarkdown :: render导致错误

render.file <-"rep.Rmd" 
    render.file <- system.file(TEMPLATES.PATH, render.file, package=getPackageName()) 
    render.dir <- dirname(render.file) 
    pdf.file <- "example.pdf" 
    rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document", 
       output_file = pdf.file) 

它的工作原理。

但如果我最后一行改为:

rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document", 
        output_file = "d:/help/me/please/example.pdf") 

它不工作(所有路径都存在)。我有错误

"! Undefined control sequence. \[email protected] ->d:\help \me\please\example _files/figure-... l.148 ...example_files/figure-latex/unnamed-chunk-2-1}"

pandoc.exe: Error producing PDF Show Traceback Rerun with Debug Error: pandoc document conversion failed with error 43 "

当我使用这个变体Linux服务器上它也可以

附:我想强调的是,问题可能不在路径中(我使用标准过程file.path()来避免系统问题,仅在示例中使用示例中的路径)。

+0

在Windows中,路径必须以另一种方式写入,而不是Linux:'D:\ help \ me \ please \ example.pdf'。我认为这是错误。 –

+0

@J_F我不这么认为,顺便说一句,我使用标准函数file.path()。在我的描述中,我只写了这个“d:/help/me/please/example.pdf”为例 – Stanislav

回答

2

也许这不是一个很好的解决办法,但它适用于WIN

lol <- rmarkdown::render(render.file , quiet = TRUE, 
       output_format = "pdf_document") 
file.rename(lol, pdf.file) 
+1

谢谢,它的工作原理,但我有一些Linux服务器的权限问题,不想移动文件 – Stanislav

1

你可以尝试使用rmarkdown::render()功能output_dir参数。

+0

不幸的是,它产生同样的错误 – Stanislav