Rmarkdown renders index.html in parent directory instead of rendering the opened document

Viewed 169

I have a directory containing slides in a bookdown directory as follows.

docs
slides/01_slide.Rmd
slides/_output.yml
01_chapter.Rmd
_bookdown.yml
_output.yml
index.Rmd
...

I would like to build the slides/01_slide.Rmd using slides/_output.yml. When I open the slides/01_slide.Rmd in RStudio and hit the Knit button, the index.Rmd is rendered instead and the file that I have actually open is not used at all.

==> rmarkdown::render_site('…/slides/01_slide.Rmd',  encoding = 'UTF-8');


processing file: bookdown.Rmd
  |......................................................................| 100%
   inline R code fragments


…
output file: bookdown.knit.md


Output created: docs/index.html

Output created: …/docs/index.html

When I rename index.Rmd to something else, then slides/01_slide.Rmd is rendered correctly.

Is there any way to force the Knit button to render the actually opened document instead of looking for input from parent directory?

I know that I can add knit: rmarkdown::render in YAML and write parameters for each slide document separately but that is even more cumbersome than constantly renaming index.html.

(The reason that I keep slides in a bookdown directory is that I want to host the entire project in a Github repository while serving the bookdown output from /docs.)

1 Answers

The problem can be solved by adding only knit: rmarkdown::render in YAML. Then the Knit button triggers render instead of render_site. No additional parameters are necessary to the function and also the slides/_output.yml is applied.

Related