Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

How to Combine R-Markdown and GitHub

Let’s see how we can create and push an R-Markdown document from RStudio to
GitHub.

Photo by Roman Synkevych on Unsplash

Version control is a great feature if you’re working in a team or even if you’re simply
working on a project. Today, we’ll see how we can combine RStudio, a must-have
software to code in R, and the features of GitHub.

The first thing to do is to create a new repository on GitHub, give it the name of your
project. You don’t need to initialize the repository with the readme.md file (you can add
this file later).

Now, we move to RStudio to create a new project, all we have to do is to follow this path:

File -> New Project -> Version Control -> Git


Now back to our repository on GitHub, we need to copy the URL of the repository, you
can copy it with Ctrl + V or with the method you prefer.

At this point we can create the R-markdown file on RStudio:

File -> New -> Markdown, enter Title, etc.

Once in the Markdown window, we need to change “output=html_document” to


“output=github_document”.

Now let’s click on Knit, to Knit the document for the first time, and RStudio will prompt
us to save the document. We then save the file as Title.rmd.

In the “git” tab of the R studio Environment window, you will notice that the knit
produced the following:

Title.rproj

Title.rmd

Title.md

Changing output to github_document makes the original .rmd knit to .md so the code
can be rendered when pushed to Git.

In the Git window, check the box to stage Title.md [attention, NOT .rmd]

Click “commit,” add comment and click the green arrow to push to GitHub.

Go to GitHub, refresh the repository, and the markdown document with rendered code
will be there!
What if our document includes graphs?

No problem, when you knit, a new file will save to the Git window, called Title.docs.
When you commit, check the box to stage the .docs in addition to the .md document.
This will commit the graphs as a separate file to the repository, although the graphics
will automatically pull into the markdown document when rendered.

Conclusion
Congratulations! You have just learned how to connect R-markdown and GitHub

You might also like