相关疑难解决方法(0)

带编织的字幕循环

我想知道是否有一种简单的方法来生成一堆带有可变标题的表格或图形knitr.我知道的唯一方法是:(简化自https://github.com/yihui/knitr-examples/blob/master/075-knit-expand.Rnw).但是src在循环之后收集输出然后打印它是一种拖累,因为我想编写一个函数来从任意数据集生成这样的循环.

\documentclass{article}
\title{Using knit\_expand() for templates}
\author{Yihui Xie}
\begin{document}

\maketitle
\tableofcontents

<<lm-mtcars, tidy.opts=list(width.cutoff=55)>>=
# the template
tpl = c("\\subsection{Regression on {{xvar}}}",
        "<<lm-{{xvar}}>>=",
        "lm(mpg~{{xvar}}, data=mtcars)",
        "@")
# expand to knitr source and pass to knit()
src = lapply(names(mtcars)[-1], function(xvar) {knit_expand(text = tpl)})
@

\Sexpr{knit(text = unlist(src))}

\end{document}
Run Code Online (Sandbox Code Playgroud)

所以我想要做的就是这样:

\documentclass{article}
\title{Using knit\_expand() for templates}
\author{Yihui Xie}
\begin{document}

\maketitle
\tableofcontents

<<lm, tidy.opts=list(width.cutoff=55)>>=
    myLfFun=function(dataset){
... some function definition which produces say an lm for each variable in dataset …
Run Code Online (Sandbox Code Playgroud)

r knitr reproducible-research

5
推荐指数
1
解决办法
2002
查看次数

标签 统计

knitr ×1

r ×1

reproducible-research ×1