2017-04-16 42 views
0

我有一個R-Markdown文件,其中包含一些我想編成pdf的HTML輸出。我的問題是,是否有一種捕獲Viewer的輸出並自動包含它的方法。Include Viewer-PDF輸出

例如,請考慮以下MWE:

--- 
title: "Include Viewer in PDF" 
author: "Myself" 
date: "today" 
output: 
    pdf_document: default 
always_allow_html: yes 
--- 
```{r} 
library(stringr) 
str_view("hello world", "o\\s[sw]") 
``` 

如果我用編織到HTML,結果正確顯示: image1

如果我用編織成PDF,不顯示結果在所有的(因爲我用always_allow_html: yes,但是如果我排除規格,我得到的錯誤: Error: Functions that produce HTML output found in document targeting latex output. ...): image2

有什麼想法?

回答

0

好吧,我找到了解決方案。感謝this question,它指引我走向webshot-library。

因此,如果需要,安裝webshot並運行webshot::install_phantomjs()。現在knitr能夠自動截取查看器。

的PDF碼以上,現在產量:

enter image description here