在 RHTML 脚本中包含一个 HTML 片段的简单明了的内容

Simple, plain include of a HTML snippet inside a RHTML script

我想创建一些包含静态 HTML 的 .rhtml 文件。想想 class 的某些页面,其中包含生成的 HTML 文件中的常见免责声明。我不想用免责声明更改所有 RHTML 文件,因此包含外部 HTML-only,没有 R 片段的想法。

我已经检查了答案 here 但它似乎对我想要的东西来说太复杂了。

我的免责声明如下:

We don't need no stinking disclaimers.

我想将它包含在 .rhtml 文件中,其中包含类似

的内容
<!--begin.rcode echo=FALSE
knit_child('_about.Rhtml')
end.rcode-->

在生成的 .html 文件中,我得到了 _about.Rhtml 的评估结果,但没有得到内容。

一件可行的事情是将 HTML 片段创建为普通 HTML 并在主 .Rhtml 中执行

<!--begin.rcode echo=FALSE,results='asis'
writeLines(readLines('_about.Rhtml'))
end.rcode-->

这行得通,但是有simple/better/more灵活的方法吗?

请指教。我正在使用 RStudio。谢谢。

像这样使用子块选项可能最简单:

<!--begin.rcode child="disclaimer.html"
-->

您可以只调用文件 whatever.html 而不是 .rhtml。