我已经(重新)实现了一些独立于@Yihui 的功能,基于knitr
我的 panderbrew
包,如果您不想在ting之前运行,可以帮助解决此类(和类似)问题。快速演示: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
(无需对text
具有实际问题的参数使用这种麻烦的设置),并且您还可以将<% ... %>
标签用于条件条件(例如显示或不呈现报告的一部分)。<% ... %>
最重要的是:(未处理的 R 命令)和<%= ... %>
(结果由pander
)标签之间存在巨大差异。后者意味着所有返回的 R 对象都转换为 Pandoc 的降价,例如:
> 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_