13

I know making .Rmd produce .html file or .md file should use the following codes

---
title: "report"
output: html_document
---

or

---
title: "report"
output: md_document
---

But how to produce the two at the same time? I try the following, but it is not working

---
title: "report"
output: html_document, md_document
---

Another issue is that, how can I make the name of the .html file (or .md file) produced different from the .Rmd file? For example, I have sample.Rmd, but I want the .md file to be named as sample_1.md.

andschar
  • 3,504
  • 2
  • 27
  • 35
Ding Li
  • 673
  • 1
  • 7
  • 19

2 Answers2

18

You can use keep_md: yes to keep the md file while still getting other output. So the YAML will be something like

---
title: "report"
author: "me"
date: '2016-04-25'
output:
  html_document:
    keep_md: yes
---
Richard Telford
  • 9,558
  • 6
  • 38
  • 51
1

You can customise the knit button, so that you can simultaneously render one Rmd file to multiple outputs. Press knit button once, and then get two outputs (.html/.md) from the example below.

---
knit: (function(input, ...) {
    rmarkdown::render(
      input,
      output_format = "all"
    ))}

title: "report"

output:
  html_doclument:
    number_sections: true
    toc: true    
  md_document:
    variant: "markdown"
    number_sections: false
    toc: false
---
Carlos Luis Rivera
  • 3,108
  • 18
  • 45
  • Actually the concept is good. But this piece of code share by you contains three quotes, while in the tutorial link you sent , the code has a different structure. The one in the tutorial works, and the one posted in this link does not. https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html – Corina Roca Jul 11 '23 at 14:15
  • @CorinaRoca I fixed my code; I should have used `---` (yaml block), not ordinary code block. In the comment you wrote above, do you mean my answer did not work for you? I would like you to tell me what error happend when you tried the code. – Carlos Luis Rivera Jul 14 '23 at 09:54
  • 1
    Hi @Carlos Luis Rivera. My case was a bit different. And this piece of code did not work for me when adding the statements after the `knit` call. Whit the knit alone it was working , although I needed to add more YAML code. As I commented, I ended up integrating all details I needed into the knit statement and it runs fair enough now. Anyway thank you for the links posted! – Corina Roca Jul 15 '23 at 12:43
  • I fixed my code again; I added `)}` to end `knit` command... – Carlos Luis Rivera Jul 16 '23 at 09:57