Using Sexpr {} Inside \ SweaveInput {}

I have two lines of code that I run using the R Sweave function.

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

The first line leads to the inclusion of the contents of the corresponding file, and the second simply calls up the word Sexpr {}, but nothing else. I want both: first evaluate the term Sexpr {}, and then include the corresponding contents of the file.

How to solve this? Thanks

+4
source share
1 answer

If you use the knitr package, the solution will be simple

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

Sweave is much weaker than knitr in terms of programmability. For example, knitr allows chunk parameters to be any valid R expressions, so we can write child=args$samples here; knitr will evaluate chunk parameters as function arguments.

BTW, the child parameter is equivalent to \SweaveInput{} , but I strongly recommend \SweaveInput{} using the pseudo LaTeX command. For more on Sweave vs knitr see http://yihui.name/knitr/demo/sweave/

+3
source

Source: https://habr.com/ru/post/1435010/


All Articles