如何在r markdown文件中编写pdf文件?

时间:2018-03-27 06:23:15

标签: rstudio r-markdown knitr miktex

我从Roger Peng的教程中复制了一个r markdown文件。我能够编织到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。

如果有人能提供帮助,我感激不尽。

1 个答案:

答案 0 :(得分:2)

如果你点击&#34; knit&#34;之后的小箭头。你应该能够编织成pdf&#34;。然后,R markdown会将正确的YAML标题添加到您的文档中:

&#13;
&#13;
Stack
&#13;
&#13;
&#13;

这对我有用。只需插入标题并单击编织。

下次:请快速查看Documentation

希望这会有所帮助:)