title: rmarkdown knitr child intermediate_dir
body: <p>I have a main document. Let's call it main.Rmd. In this main document I include a knitr child. Let's call this child.Rmd.  In the child.Rmd I define a variable containing the link to a file containing R chunks, called chunks.R, which I want to load using read_chunk.</p>
  
  <p>If I use the rmarkdown::render('main.Rmd') everything works fine. However, once I set the intermediate_dir to something else (e.g rmarkdown::render('main.Rmd',intermediate_dir=tempdir()) the read_chunk won't work anymore. </p>
  
  <p>If I pass the filepath directly to read_chunk instead of defining it in a variable it works again. I need to pass the filename via variable however.</p>
  
  <p><em>main.Rmd</em></p>
  
  <pre><code>---
  output: pdf_document
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = TRUE)
  ```
  
  
  ```{r,child='~/Desktop/knitr_problem/child.Rmd',}
  ```
  </code></pre>
  
  <p><em>child.Rmd</em></p>
  
  <pre><code>```{r}
  chunkpath=normalizePath('~/Desktop/knitr_problem/chunks.R')
  knitr::read_chunk(chunkpath)
  ```
  
  
  ## Including Plots
  
  You can also embed plots, for example:
  
  ```{r cars, echo=FALSE}
  ```
  </code></pre>
  
  <p><em>chunks.R</em></p>
  
  <pre><code>## @knitr cars
  summary(cars)
  </code></pre>
  
  <p>render(main.Rmd) will work</p>
  
  <p>render(main.Rmd,intermediate_dir=tempdir()) won't work and throw the following error
  Error in readLines(path, warn = FALSE) : object 'chunkpath' not found</p>