rmarkdown里运行html文件,在R Markdown文件中包含HTML文件?

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文件:

Title

This 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值