3
使用準備報告時:http://rmarkdown.rstudio.com/根據文檔類型,可能需要文檔進行不同的呈現。例如,如果正在呈現的文檔是HTML文件,我想要嵌入YouTube視頻,就好像它是pdf或MS Word一樣,我希望使用超鏈接的URL。ifelse根據rmarkdown中的文檔類型採取的行動
有沒有辦法告訴是這樣的:
if (html) {
<iframe width="640" height="390" src="https://www.youtube.com/embed/FnblmZdTbYs? feature=player_detailpage" frameborder="0" allowfullscreen></iframe>
} else {
https://www.youtube.com/watch?v=ekBJgsfKnlw
}
代碼
devtools::install_github("rstudio/rmarkdown")
library(rmarkdown)
render("foo.Rmd", "all")
foo.Rmd
---
title: "For Fun"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
toc: true
theme: journal
number_sections: true
pdf_document:
toc: true
number_sections: true
word_document:
fig_width: 5
fig_height: 5
fig_caption: true
---
## Good times
<iframe width="640" height="390" src="https://www.youtube.com/embed/FnblmZdTbYs?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>
感謝您的回答。我應該回答這個,因爲我前一段時間找到了答案:https://trinkerrstuff.wordpress.com/2014/11/18/rmarkdown-alter-action-depending-on-document/ – 2015-04-28 19:02:50