【问题标题】:Remove <code> tag from inline Rhtml knitr code从内联 Rhtml knitr 代码中删除 <code> 标记
【发布时间】:2013-03-12 18:33:33
【问题描述】:

在编写 Rhtml 文档时,您可以利用&lt;!--rinline x --&gt; 在 Rhtml 文档中编写内联代码。但是,此代码包含在 &lt;code class="inline knitr"&gt;x&lt;/code&gt; 中,这可能会破坏基本格式。

有没有办法完全删除它?这样只有x 被写入文档。

【问题讨论】:

    标签: r knitr


    【解决方案1】:

    我假设您的意思是只有 x 中存储的内容的输出才会写入文档。您可以通过将表达式包装在 I() 中来获得此信息。

    比较一下这个输出的差异:

    <html>
    
    <head>
    <title>Title</title>
    </head>
    
    <body>
    
    <p>Test document</p>
    
    <!--rinline x <- 3 -->
    
    <!--rinline x -->
    
    <!--rinline I(x) -->
    
    </body>
    </html>
    

    这将产生以下主体:

    <body>
    
    <p>Test document</p>
    
    
    
    <code class="knitr inline">3</code>
    
    3
    
    </body>
    

    我们可以看到第一个 rinline 获取代码标签,而第二个只是将输出直接插入到文档中。

    【讨论】:

    • 感谢 Dason,他解释了“Luke, use the source”问题 :)
    • 有趣,我以前从未听说过I()
    • @BrandonBertelsen 如果您正在使用 knitr,这是一本不错的读物 - yihui.name/knitr/demo/output
    • Ack,我在该页面中搜索 RHTML 而不是 R HTML。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 2012-06-16
    • 2012-08-08
    • 2016-07-15
    相关资源
    最近更新 更多