41

I am working on a website with Rmarkdown on gh-pages. However, in R studio you can only create new .Rmd files. This is a problem because I need to convert my .Rmd files into .md files before I push to my github repo.

Does anyone have some advice?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Gustavo B Paterno
  • 976
  • 1
  • 9
  • 14

1 Answers1

65

Since you're using RStudio, I'll refer to the documents they provide. Specifically, Markdown Documents, accessible by clicking on the question mark pull-down next to "Knit", select "Using R Markdown" which takes you to their webpage. From there, select "Formats > Markdown".

That page shows you that if you include the following in the YAML (first lines of the document, different kind of meta/markup as markdown), the output will be a .md file:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
---

(The only relevant part is the output: portion.) In fact, since you mentioned gh-pages, you may (though not necessarily) want to choose the github-flavor of markdown with this instead:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output:
  md_document:
    variant: markdown_github
---

From here, click on the "Knit" button and you will get your .Rmd-to-.md conversion.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Just what I wanted, thanks. But I got and error using *markdown_github*. It worked using *github_document* instead. Maybe they renamed it? – ddiez Dec 04 '16 at 14:24
  • 3
    [`md_document`](http://rmarkdown.rstudio.com/markdown_document_format.html) and [`github_document`](http://rmarkdown.rstudio.com/github_document_format.html) are different *output formats*. Within the first is a variant called `markdown_github`. `github_document` is just a [special-case of `md_document`](https://github.com/rstudio/rmarkdown/blob/master/R/github_document.R#L36) that sets the variant to `markdown_github`. This example still works for me. What is the error? – r2evans Dec 04 '16 at 18:01
  • It seems to be important to put the arguments on separate lines as is shown in the example. If I put "output:" and "md_document:" on the same line I get the error "Error in yaml::yaml.load(string, ...) : Scanner error: mapping values are not allowed in this context at line 4, column 20 Calls: ... parse_yaml_front_matter -> yaml_load_utf8 -> -> .Call Execution halted". Maybe that is what ddiez was referring to. – Justin Meyer Dec 17 '17 at 14:00
  • I have two comment lines in my R scipt file, starting with `#'` and end of each lines ends with two spaces ` ` for indicating new line in generated .Rmd file. But, when I convert to .md file the new lines are lost (two spaces disappear). How can I restore the new lines in md file? – Gürol Canbek Feb 03 '18 at 06:09
  • It's not good to ask a new question as a comment to an answer for another question. It is often okay if it is strongly related, but there is too little here to provide any confident response. I suggest you ask a new question and include a MWE. – r2evans Feb 03 '18 at 08:17