Changing default behavior of Knit button

Recently, I am facing this strange issue with the "Knit" button in RStudio. Whenever I try to knit an R Markdown file using the "Knit" button, it uses the "rmarkdown::render_site" function to knit the file. I am trying to knit a single .Rmd file, and not a bookdown book or site. Thus, this function creates a _main.Rmd file in the default working directory. This happens even when I am working inside an RStudio project, and irrespective of any output format I choose (PDF/HTML/Word).
However, if I add extra line in YAML header like following, then I can knit a PDF from the .Rmd file.

---
knit: rmarkdown::render
---

I contacted the developer Yihui Xie over github, and he suggested me to take help from this wonderful community. He also pointed me out to an article, so that I can access the RStudio preferences. But I don't know which setting I need to change in which particular file.

Finally, with the help of @yihui and @cderv , I found the reason. The default working directory (the one from the Tools Menu > Global Options > General, there is a setting "Default working directory (when not in a project)) had an index.Rmd file. Therefore, R Markdown assumed that my project was a book project. Once I deleted _main.Rmd from this default working directory, and moved the index.Rmd file to a different folder, the Knit button works properly now.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.