Skip to content

Instantly share code, notes, and snippets.

@JoshuaTPierce
Created June 7, 2017 17:21
Show Gist options
  • Select an option

  • Save JoshuaTPierce/b919168421b40e06481080eb53c3fb2f to your computer and use it in GitHub Desktop.

Select an option

Save JoshuaTPierce/b919168421b40e06481080eb53c3fb2f to your computer and use it in GitHub Desktop.
Creating and Pushing a R-Markdown Document to Github (including graphs)
Go to github
Create new repository [don't need to initialize with the readme (can add later)]
Go to R Studio
File -> New Project -> Version Control -> Git
Ctrl+V repository URL from GitHub
File -> New -> Markdown, enter Title, etc.
In the Markdown window, change "output=html_document" to "output=github_document"
Knit the document for the first time, will prompt you to save
Save as Title.rmd
In the "git" tab of the R studio Environment window, you will notice that the knit produced:
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 [NOT .rmd]
Click "commit," add comment.
Click the green arrow to push to GitHub.
Go to GitHub, refresh the repository, and the markdown document with rendered code will be there
IF YOUR DOCUMENT INCLUDES GRAPHS:
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 in to the markdown document when rendered.
@RodriDuran

Copy link
Copy Markdown

Thanks!

@Zaryn-Ooi

Copy link
Copy Markdown

Thanks Joshua ! Very helpful !

@nicoleludwiak

Copy link
Copy Markdown

Thank you so much for this post, Joshua!

ghost commented Oct 24, 2021

Copy link
Copy Markdown

I got lost somewhere along the way I think because you have used mac and I have windows.

@Roljed

Roljed commented Nov 15, 2021

Copy link
Copy Markdown

Thanks a lot Joshua!

@shangeconnew

Copy link
Copy Markdown

Hi Joshua, there is no file at all when I open the Git window; so I got no file to stage. I wonder if you could help me with that. Thanks!

@ro-zeta

ro-zeta commented Feb 24, 2022

Copy link
Copy Markdown

@shangeconnew this may be too late, but the way it worked for me is I configured my git repository on GitHub, then cloned it to the local machine, then I was able to use "git commit" and "git push" commands in the terminal to merge files to that Github repository.

@petmat01

petmat01 commented Apr 2, 2022

Copy link
Copy Markdown

Thank you very much, Joshua.

@bunnyk1012

Copy link
Copy Markdown

Thank you so much !

@friendly

friendly commented Jun 9, 2022

Copy link
Copy Markdown

Oh, this seems like so much work in github compared with just using markdown'd R notebook in RStudio and then publishing to Rpubs! But thanks for showing the details of doing a github gist.

@vivekjoshi5

Copy link
Copy Markdown

@friendly What's the faster alternative to upload to GitHub ? 🤔
I am trying to push to github so I can deploy my R code to github pages.
Thanks @JoshuaTPierce for the instructions. 🎉

@gulla0

gulla0 commented Aug 7, 2022

Copy link
Copy Markdown

Thank you!

@gabridinosauro

Copy link
Copy Markdown

nothing appears in ,my repository although I follow all steps... I hate github

@sonick1

sonick1 commented Nov 1, 2022

Copy link
Copy Markdown

Thanks

@joannapeck

Copy link
Copy Markdown

excellent post! so helpful!

@JoeJoe1313

Copy link
Copy Markdown

Very helpful! Thanks!

@sydneydlu98

Copy link
Copy Markdown

Very useful!

@noschenk

Copy link
Copy Markdown

Thanks so much, exactly what I needed!

@mickeykawai

Copy link
Copy Markdown

Fantastic! Thank you very much! Great developers and great Joshua!

@stephrlo

stephrlo commented Jun 2, 2023

Copy link
Copy Markdown

Thank you for this. This is exactly what I needed!

@Zeegaths

Zeegaths commented Jun 3, 2023

Copy link
Copy Markdown

so helpful

@SaumiRah

SaumiRah commented Jun 6, 2023

Copy link
Copy Markdown

Any advice on getting latex to render properly?

@amhoesk

amhoesk commented Jun 11, 2023

Copy link
Copy Markdown

Tnx. So helpful.

@dhumantorch

dhumantorch commented Jul 30, 2023

Copy link
Copy Markdown

For me, the graphs were stored in Title_files so I just added that instead of .docs. Worked anyway!

@skhan123-noncoder

Copy link
Copy Markdown

Thanks for the post! Very helpful

@s-sawadogo

Copy link
Copy Markdown

Thanks, Yoshua. So helpful !

@Sofia-A-Fayo-Freites

Copy link
Copy Markdown

Very useful thank you!

@nasreenfsayeed

Copy link
Copy Markdown

Got a Git Commit message mentioning it is unable to verify me and asked me who I am. But the Git Commit window is not allowing me to type my email address and username in it. Kindly help

@knchar2

knchar2 commented Feb 19, 2025

Copy link
Copy Markdown

The instructions here say the Title.md file (NOT Title.rmd) but all I have is the rmd file. There is no md file in the Git window. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment