title: Source code from Rmd file within another Rmd
body: <p>I'm attempting to make my code more modular: data loading and cleaning in one script, analysis in another, etc. If I were using R scripts, this would be a simple matter of calling <code>source</code> on <code>data_setup.R</code> inside <code>analysis.R</code>, but I'd like to document the decisions I'm making in an Rmarkdown document for both data setup and analysis. So I'm trying to write some sort of <code>source_rmd</code> function that will allow me to source the code from <code>data_setup.Rmd</code> into <code>analysis.Rmd</code>.</p>
  <h3>What I've tried so far:</h3>
  <p>The answer to <a href="https://stackoverflow.com/questions/10966109/how-to-source-r-markdown-file-like-sourcemyfile-r">How to source R Markdown file like `source(&#39;myfile.r&#39;)`?</a> doesn't work if there are any repeated chunk names (a problem since the chunk named <code>setup</code> has special behavior in Rstudio's notebook handling). <a href="https://stackoverflow.com/questions/25824795/how-to-combine-two-rmarkdown-rmd-files-into-a-single-output">How to combine two RMarkdown (.Rmd) files into a single output?</a> wants to combine entire documents, not just the code from one, and also requires unique chunk names. I've tried using <code>knit_expand</code> as recommended in <a href="https://stackoverflow.com/questions/21729415/generate-dynamic-r-markdown-blocks/21730473#21730473">Generate Dynamic R Markdown Blocks</a>, but I have to name chunks with variables in double curly-braces, and I'd really like a way to make this easy for my colaborators to use as well. And using <code>knit_child</code> as recommended in <a href="https://stackoverflow.com/questions/17535227/how-to-nest-knit-calls-to-fix-duplicate-chunk-label-errors">How to nest knit calls to fix duplicate chunk label errors?</a> still gives me duplicate label errors.</p>