Professional Documents
Culture Documents
How To Combine R-Markdown and GitHub - by Fabrizio Cominetti - Geek Culture - Medium
How To Combine R-Markdown and GitHub - by Fabrizio Cominetti - Geek Culture - Medium
Let’s see how we can create and push an R-Markdown document from RStudio to
GitHub.
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:
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