Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用knitr设置HTML元元素_Html_R_Knitr_Literate Programming - Fatal编程技术网

使用knitr设置HTML元元素

使用knitr设置HTML元元素,html,r,knitr,literate-programming,Html,R,Knitr,Literate Programming,我正在使用knitr生成HTML报告,并且我希望包含author和generationdate元标记 我的Rhtml页面看起来像这样 <html> <head> <meta name="author" content="<!--rinline Sys.getenv('USERNAME') -->"> <meta name="date" content="<!--rinline as.character(Sys.time()) -

我正在使用knitr生成HTML报告,并且我希望包含author和generationdate元标记

我的Rhtml页面看起来像这样

<html>
<head>
  <meta name="author" content="<!--rinline Sys.getenv('USERNAME') -->">
  <meta name="date" content="<!--rinline as.character(Sys.time()) -->"> 
</head>
<body>
</body>
</html>
这不是有效的HTML。我真正想要生成的是

  <meta name="author" content="RCotton">
  <meta name="date" content="2013-01-02 14:38:16">

我可以生成不包含
code
标记的R代码吗?或者是否有其他方法来指定标记属性(如这些内容属性)


到目前为止,我最糟糕的计划是用
readLines
/
str\u replace
/
writeLines
手动修复内容,但这似乎相当困难。

不是很好,但似乎在不添加挂钩的情况下也能工作:

<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>

"> 
“,sep=”“)
end.rcode-->
另一种(未记录的)方法是在内联代码周围添加
I()
,以按原样打印字符,而不使用
标记,例如

<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>


您也可以简单地
brew
该文件。我相信新添加的
knit_-expand
函数在这里会很理想。通过先通过
knit_-expand
传递一个文件,然后再通过
knit2html
,您可以轻松实现
brew
knitr
的最佳效果。也许@Yihui可以添加到这一点。@dietermene当然,我会的l添加到网站;@Ramnath在这种情况下,
如果文件中有更多的块,则不是一个坏选择,
knit_expand()
将是
knit()之前的附加步骤
@yihui是有道理的。但是knit_expand提供了Sweave用户长期以来一直寻求的类似于brew的功能。减少工具链的一种方法是允许用户指定
opts_knit$set(expand=TRUE)
它将在编织之前通过
knit\u expand
运行文档。或者,可以使用文档挂钩来实现,我认为这更有意义,因为knit\u expand可以使用来自父帧的数据。
<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>