user1240076
user1240076

Reputation: 303

Using Sexpr{} within \SweaveInput{}

I have this 2 lines of code which I run with R Sweave function.

\SweaveInput{samples.rnw}
\SweaveInput{\Sexpr{args$samples}}

The first line leads to the inclusion of the content of the corresponding file, while the second just causes evaluation of the Sexpr{} term but nothing else. What I want is both: first let evaluate the Sexpr{} term and afterwards do the inclusion of the respective file content.

How do solve this ? Thanks

Upvotes: 4

Views: 303

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30114

If you use the knitr package, the solution would be simply

<<child='samples.rnw'>>=
<<child=args$samples>>=
@

Sweave is much weaker than knitr in terms of programmability. For example, knitr allows the chunk options to be any valid R expressions, which is the reason why we can write child=args$samples here; knitr will evaluate the chunk options just like function arguments.

BTW, the child option is equivalent to \SweaveInput{}, but I strongly discourage the use of the pseudo LaTeX command. For more about Sweave vs knitr, see http://yihui.name/knitr/demo/sweave/

Upvotes: 3

Related Questions