Search code examples
rcranroxygen2

How to generate README.md from README.Rmd for R package?


Inspecting dplyr shows there's both a README.md file and a README.Rmd file.

In the .md file, it says

README.md is generated from README.Rmd. Please edit that file

It's easy enough to create the .Rmd file, but how then is the .md file generated? Is it using roxygen2 or is there some terminal command (or something else)?


Solution

  • Simply set output: github_document in the yaml at the top of the .Rmd and click knit.

    Here's a small but complete RMarkdown document as an example:

    ---
    output: github_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## R Markdown
    
    This is an R Markdown document that generates a github readme.md file.
    
    ```{r}
    summary(iris)
    ```
    

    Then simply click 'knit' like so:

    enter image description here

    Note:

    • for markdown document that is strictly 'markdown' (as opposed to github flavored markdown), use output: md_document instead (but if it's for a github readme, you'll most likely want the github flavored version)