chinsoon12..
12
这是一个hack(可能不太优雅)...想法是在Rmd中以编程方式直接插入HTML然后渲染Rmd.
temp.Rmd文件:
---
title: "Introduction"
author: "chinsoon12"
date: "April 10, 2016"
output: html_document
---
<
etc, etc, etc
```{r, echo=FALSE}
htmltools::includeHTML("test.html")
```
etc, etc, etc
test.html文件:
TitleThis is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
test test
详细代码用HTML代码替换Rmd代码然后渲染(可能会被缩短很多)
library(stringi)
subHtmlRender
#replace <
#but without beginning white space
lines
toSubcode
location
htmllines
#render html doc
newRmdfile
newlines
htmllines,
lines[min(location+1, length(lines)):length(lines)]) #be careful when insertHTML being last line in .Rmd file
write(newlines, newRmdfile)
rmarkdown::render(newRmdfile, "html_document")
shell(gsub(".Rmd",".html",basename(newRmdfile),fixed=T))
} #end subHtmlRender
subHtmlRender("temp.Rmd", "test.html")
编辑:htmltools :: includeHTML也适用于我提供的示例文件.是因为你的特定html不喜欢UTF8编码吗?
编辑:将@MikeWilliamson评论纳入反馈意见
我尝试了以下内容
删除对cloudfare.com的引用,因为我在渲染时遇到了访问问题(见下文)
编织HTML
放回那些云计算网络链接
将图形放在与渲染的html相同的文件夹中
打开HTML
我似乎找回了html但不确定结果是否符合您的预期
您是否也在第2页面临同样的问题?您可能希望发布错误消息并要求修复:).这是我的错误信息
pandoc.exe: Failed to retrieve http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css
FailedConnectionException2 "cdnjs.cloudflare.com" 80 False getAddrInfo: does not exist (error 11001)
Error: pandoc document conversion failed with error 61