ting の前に実行したくない場合に、このような (および同様の) 問題に役立つ可能性がある、私のパンダー パッケージknitr
に基づいて、@Yihui とは独立していくつかの機能を (再) 実装しました。クイックデモ:brew
brew
knit
> Pandoc.brew(text = "# Demonstrating a nice loop
+ <% for (i in 1:5) { %>
+ ## This is a header for <%=i%>
+ #' This is a comment for <%=i%>
+ <% } %>")
# Demonstrating a nice loop
## This is a header for _1_
#' This is a comment for _1_
## This is a header for _2_
#' This is a comment for _2_
## This is a header for _3_
#' This is a comment for _3_
## This is a header for _4_
#' This is a comment for _4_
## This is a header for _5_
#' This is a comment for _5_
ファイルを に渡すこともできます(実際の問題を伴う引数でPandoc.brew
このような面倒な設定を使用する必要はありません)。また、たとえば条件 (レポートの一部を表示する、またはレンダリングしないなど) にタグを使用することもできます。そして最も重要なことは、 (未処理の R コマンド) タグと(結果が によって処理される) タグの間には大きな違いがあることです。後者は、返されたすべての R オブジェクトが Pandoc のマークダウンに変換されることを意味します。text
<% ... %>
<% ... %>
<%= ... %>
pander
> Pandoc.brew(text = "# Demonstrating a conditional
+ <% for (i in 1:5) { %>
+ ## This is a header for <%=i%>
+ <% if (i == 3) { %>
+ Hey, that's **almost** <%=pi%>, that's between <%=3:4%>! Wanna fit a model to _celebrate_?
+ <%= lm(mpg ~ hp, mtcars) %>
+ <% }} %>")
# Demonstrating a conditional
## This is a header for _1_
## This is a header for _2_
## This is a header for _3_
Hey, that's **almost** _3.142_, that's between _3_ and _4_! Wanna fit a model to _celebrate_?
--------------------------------------------------------------
Estimate Std. Error t value Pr(>|t|)
----------------- ---------- ------------ --------- ----------
**hp** -0.06823 0.01012 -6.742 1.788e-07
**(Intercept)** 30.1 1.634 18.42 6.643e-18
--------------------------------------------------------------
Table: Fitting linear model: mpg ~ hp
## This is a header for _4_
## This is a header for _5_