How to produce both .html and .md from an .Rmd (Rmarkdown) and rename them?
Asked Answered
I

2

15

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.

Istanbul answered 5/1, 2017 at 11:1 Comment(0)
A
21

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
---
Alumroot answered 5/1, 2017 at 11:3 Comment(4)
How about the names? Can I modify it somehow?Istanbul
I don't think you can change the output filenames with YAML. So foo.Rmd will give foo.html and foo.mdAlumroot
Please refer here for changing the doc name http://stackoverflow.com/questions/28500096/r-markdown-variable-output-nameMiele
Future user: be careful with spaces vs tabs. Don't mix them!Raffish
W
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
---
Witte answered 30/11, 2022 at 10:11 Comment(4)
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. bookdown.org/yihui/rmarkdown-cookbook/custom-knit.htmlPyroxenite
@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.Witte
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!Pyroxenite
I fixed my code again; I added )} to end knit command...Witte

© 2022 - 2024 — McMap. All rights reserved.