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/
source share