[R] Sweave - How to use local objects in code chunks

Ista Zahn istazahn at gmail.com
Sat Jan 16 23:29:56 CET 2010

I don't think it works that way. The .Rnw file should be
self-contained. Put all the R code in the .Rnw file (or keep it in a
separate file and source() it into the .Rnw file).

-Ista

On Sat, Jan 16, 2010 at 3:35 PM, Jan-Henrik Pötter
<henrik.poetter at gmx.de> wrote:
> Hello,
>
> I wrote a function create_report that calls the function Sweave.
> create_report shall be used to create a pdf-report about an lm-Object which
> is passed as an argument to create_report.
>
> I try to use an object sel_model, that is created within the function
> environment of create_report and later on used within the first code chunk
> of the file report_template.rnw.
>
> When I use following code I get an error message that the object sel_model
> could not been found. How can I achieve to use objects within code-chunks
> that are not globally available, but only within my function call of
> create_report? Is it only possible to use globally available objects within
> a code chunk?
>
>
>
> create_report<-function(model_lst){
>
> #define parameters
>
> sel_model<-model_lst
>
> Sweave('report_template.rnw')
>
> tools::texi2dvi("report_template.tex", pdf=TRUE)
>
> }
>
>
>
> create_report(p3)
>
>
>
>
>
> this is the file report_template.rnw
>
>
>
> \documentclass[a4paper]{article}
>
> \begin{document}
>
>
>
> <<echo=FALSE>>=
>
> summary(sel_model)
>
> @
>
> \begin{center}
>
> <<fig=TRUE,echo=FALSE>>=
>
> plot_fx(sel_model)
>
> @
>
> \end{center}
>
>
>
> \end{document}
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Ista Zahn