我正在使用author生成HTML报告,并且我想包括作者和生成日期元标记。
我的Rhtml页面看起来像这样。
<html>
<head>
<meta name="author" content="<!--rinline Sys.getenv('USERNAME') -->">
<meta name="date" content="<!--rinline as.character(Sys.time()) -->">
</head>
<body>
</body>
</html>不幸的是,在I knit("test.Rhtml")之后,knitr生成的超文本标记语言是
<meta name="author" content="<code class="knitr inline">RCotton</code>">
<meta name="date" content="<code class="knitr inline">2013-01-02 14:38:16</code>"> 这不是有效的HTML。我真正想要生成的东西是
<meta name="author" content="RCotton">
<meta name="date" content="2013-01-02 14:38:16">我可以生成不使用code标签包装的R代码吗?或者,有没有其他方法来指定标签属性(比如这些内容属性)?
到目前为止,我最不糟糕的计划是用readLines/str_replace/writeLines,手动修复内容,但这似乎相当笨拙。
发布于 2013-01-03 01:37:15
另一种(未记录的)方法是在内联代码周围添加I(),以打印没有<code>标记的字符,例如
<html>
<head>
<meta name="author" content="<!--rinline I(Sys.getenv('USERNAME')) -->">
<meta name="date" content="<!--rinline I(as.character(Sys.time())) -->">
</head>
<body>
</body>
</html>发布于 2013-01-03 00:30:24
不是很好,但似乎不需要添加钩子就可以工作:
<head>
<!--begin.rcode results='asis', echo=FALSE
cat('
<meta name="author" content="', Sys.getenv('USERNAME'), '">
<meta name="date" content="', as.character(Sys.time()),'-->">
',sep="")
end.rcode-->
</head>https://stackoverflow.com/questions/14124022
复制相似问题