Search code examples
rrstudior-markdownrnotebook

Default knit directory via YAML header in RStudio?


Is there a YAML option, which sets knit directory for an Rmd file? I.e. does the same as illustrated in Fig.1. The problem is that every time I copy files or share a project with other people (which usually have different default RStudio options than I do), the knit directory should be reset manually in each file. I'm aware of the global option (Fig.2), but I need a more reproducible solution which works for individual Rmd files in both both RStudio notebook and knitting modes. And, for instance, I know that there is an option such as:

editor_options: 
  chunk_output_type: console

Any ideas?

enter image description here

Fig. 1 Setting knit directory via menu commands.

enter image description here

Fig. 2 Global option to set default knit directory in RStudio.


Solution

  • You could try to specify the knit field in the front-matter of our .Rmd file. Example .Rmd that would knit into "some_dir" created in your home directory:

    ---
    title: "Untitled"
    output: html_document
    knit: (function(inputFile, encoding) {
        rmarkdown::render(inputFile, encoding = encoding, output_dir = "~/some_dir/")
      })
    ---
    
    # Some content
    
    Some content