【问题标题】:How to knit to pdf in r markdown file?如何在 r markdown 文件中编织成 pdf?
【发布时间】:2018-09-05 10:29:05
【问题描述】:

我从 Roger Peng 的教程中复制了一个降价文件。我能够编织到 html 和 Word,但在编织到 pdf 时遇到了问题。 test.Rmd 代码:

My First Knitr Document
===============================

This is some text (i.e. a text chunk).

here is a code chunk
```{r}
set.seed(1)
x <- rnorm(100)
mean(x)
```  

点击'knit to pdf'后,报错:

Output created: test.pdf
Error in tools::file_path_as_absolute(output_file) : 
file 'test.pdf' does not exist
Calls: <Anonymous> -> <Anonymous>
In addition: Warning messages:
1: running command '"pdflatex" -halt-on-error -interaction=batchmode 
"test.tex"' had status 1 
2: In readLines(logfile) : incomplete final line found on 'test.log'
Execution halted  

当我在 cmd (windows) 中运行“latexmk -version”时,我得到:

latexmk: warning: running with administrator privileges
latexmk: The script engine  could not be found
latexmk: Data: scriptEngine="perl.exe"  

我的会话信息:

R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tinytex_0.4 sp_1.2-7   

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16    lattice_0.20-35 withr_2.1.2     digest_0.6.15   
rprojroot_1.3-2 grid_3.4.4     
[7] R6_2.2.2        backports_1.1.2 magrittr_1.5    evaluate_0.10.1 
httr_1.3.1      stringi_1.1.7  
[13] rmarkdown_1.9   devtools_1.13.5 tools_3.4.4     stringr_1.3.0   
yaml_2.1.18     compiler_3.4.4 
[19] memoise_1.1.0   htmltools_0.3.6 knitr_1.20   

我的 MikTex 版本:basic-miktex-2.9.6。

更新,更准确地说,相同的代码在 mac 上运行良好(不过是 R 版本 3.4.0)。
更多信息:我在 E 盘上安装了 RStudio,而在 C 盘上安装了 MikTex。
另外,我可以使用 R Sweave 编译 pdf。

如果有人可以提供帮助,我将不胜感激。

【问题讨论】:

    标签: rstudio r-markdown knitr miktex


    【解决方案1】:

    如果您单击“编织”旁边的小箭头,您应该能够“编织到 pdf”。然后,R markdown 会将正确的 YAML 标头添加到您的文档中:

    ---
    output:
      pdf_document: default
    ---
    My First Knitr Document
    ===============================
    
    This is some text (i.e. a text chunk).
    
    here is a code chunk
    ```{r}
    set.seed(1)
    x <- rnorm(100)
    mean(x)
    ```  

    这对我有用。只需插入 Header 并单击 knit。

    下次:请速看Documentation

    希望这会有所帮助:)

    【讨论】:

    • 感谢 Kaktus。我有标题,只是忘记发布了。即使没有标头,我也可以在 mac 上成功运行 Rmd 文件。
    猜你喜欢
    • 2015-04-04
    • 1970-01-01
    • 2015-07-11
    • 2021-10-18
    • 1970-01-01
    • 2018-10-07
    • 2019-12-08
    • 2021-04-20
    • 1970-01-01
    相关资源
    最近更新 更多