假设我有一个简单的 rmarkdown 文档,名为 test.Rmd
---
output: pdf_document
---
This code tries to save output to a file called 'example.txt'
```{r}
sink(file='example.txt')
sink.number()
library(MASS)
summary(cars)
sink()
sink.number()
```
Run Code Online (Sandbox Code Playgroud)
如果我在 RStudio 中运行它(使用 knit PDF 按钮),那么我会得到大量输出,但我相信最重要的是以下内容(我可以根据要求包含其他输出)
processing file: test.Rmd
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\wammonj\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
output file: test.knit.md
Output created: test.pdf
Warning message:
In sink() : no sink to remove
Run Code Online (Sandbox Code Playgroud)
文件 example.txt 已创建,但输出不在那里,而 Rmarkdown 则创建了一个名为 test.pdf 的文件, …