抱歉,如果这是一个愚蠢的问题,但有人知道如何在 knitr 中循环 R 函数吗?到目前为止,我的问题是将变量从乳胶传递到 R 函数。我正在尝试做这样的事情:
\documentclass{article}
\usepackage{forloop}
\newcounter{ind}
\begin{document}
%Simple R function:
<<simpleRFun, results='asis' ,echo=FALSE>>=
simpleRFun = function(ind){
set.seed(ind) ;
plot(runif(100)) ;
}
@
%Run the function for value of 1
<<>>=
simpleRFun(1)
@
%Run the function for value of 2
<<>>=
simpleRFun(2)
@
%Loop over values of 1 and 2:
\forloop{ind}{1}{\value{ind} < 3}{
\arabic{ind}
}
%Loop over values of 1 and 2 and pass to R function:
%Everything runs fine until this line:
\forloop{ind}{1}{\value{ind} < 3}{
<<>>=
simpleRFun(ind)
@
}
\end{document}
我收到以下错误:
Runaway argument?
#### Error: object 'ind' not found \end {verbatim} \end {kframe} \end \ETC.
./knitr-minimal.tex:97: Paragraph ended before \@xverbatim was complete.
<to be read again>
\par
l.97 }
在此先感谢您的帮助。