rmarkdown knitr child intermediate_dir

Viewed 256

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.

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.

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.

main.Rmd

---
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r,child='~/Desktop/knitr_problem/child.Rmd',}
```

child.Rmd

```{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}
```

chunks.R

## @knitr cars
summary(cars)

render(main.Rmd) will work

render(main.Rmd,intermediate_dir=tempdir()) won't work and throw the following error Error in readLines(path, warn = FALSE) : object 'chunkpath' not found

0 Answers
Related