On 11/11/2009 12:09 PM, Pfaff, Bernhard Dr. wrote:
Dear list subscriber,
suppose, I do have a minimal Sweave file 'test.Rnw':
\documentclass{article}
\begin{document}
<<printx>>=
x
@
\end{document}
Within R, I define the following function:
f <- function(x){
Sweave("test.Rnw")
}
The call:
f(x = 1:10)
results in the following error message:
Writing to file test.tex
Processing code chunks ...
1 : echo term verbatim (label=printx)
Error: chunk 1 (label=printx)
Error in eval(expr, envir, enclos) : object 'x' not found
In principle, I could assign x to the global environment and
then the Sweave file will be processed correctly:
+ attach(list(x = x))
+ Sweave("test.Rnw")
+ }
Writing to file test.tex
Processing code chunks ...
1 : echo term verbatim (label=printx)
You can now run LaTeX on 'test.tex'
Kind of a dum question, but how could it be achieved that
Sweave recognizes the objects within this function call?
The way you did it is close. You can attach all the local
variables by
using
attach(environment())