11

Is there a way to knit a single .md file to a .html or .docx in the working directory in R and simultaneously post a copy of the .html to another folder, possibly on another drive?

Alternatively, can the 'publish' button in RStudio be used to send a .md file to a location other than RPubs?

J_F
  • 9,956
  • 2
  • 31
  • 55
steinbock
  • 726
  • 1
  • 12
  • 25

2 Answers2

24

Actually, the knit button can indeed -

  • Render multiple outputs.
  • Use a custom output directory.

Example with output directory called output:

title: "multiple outputs"
output:
  word_document: default
  html_document: default
knit: (function(inputFile, encoding) {
  rmarkdown::render(inputFile, encoding = encoding,
  output_dir = "output", output_format = "all") })
J_F
  • 9,956
  • 2
  • 31
  • 55
Peter Harrison
  • 873
  • 1
  • 8
  • 12
11

Yes it's possible to render multiple outputs, but not with the "knit" Button in RStudio. Write your desired output in the YAML header and then use output_format = "all" as argument in

rmarkdown::render(<your-rmd-file.rmd>, output_format ="all")

So the YAML header looks like:

title: "multiple outputs"
output:
     word_document: default
     html_document: default

Or any option you want to set for the different output formats.

I don't know if it is possible to set different output directories, but I don't think so.

J_F
  • 9,956
  • 2
  • 31
  • 55
  • 1
    A way to render it in two directories would be: `render(rmd.rmd, output_format="word_document", output_dir="./doc") ; render(rmd.rmd, output_format="html_document", output_dir="./html") ;` – scoa Sep 23 '16 at 15:35
  • That's clear ... with 2 function calls you can knit the file in two folders. – J_F Sep 23 '16 at 15:39
  • Nice one guys. Cheers! – steinbock Sep 25 '16 at 18:43