41

I am practicing data analysis using R programming. I want my files to be on github. I am unable to figure out why github is not showing the output of .rmd files.

Here is the link to the file in my github repository Data Analysis Practice

I want the output including plots to be shown on github.

Phil
  • 7,287
  • 3
  • 36
  • 66
Shankar Pandala
  • 969
  • 2
  • 8
  • 28
  • Wouldn't it just be the same as in knitr? http://stackoverflow.com/questions/22147594/export-graph-in-r-and-also-display-it-in-knitr – IRTFM Oct 02 '16 at 08:23
  • @42- I am getting the output perfectly in local machine. But after pushing this to github, It only shows code not the output. – Shankar Pandala Oct 02 '16 at 08:37
  • In order to view output in Rmd files, you need to "knit" them. This is a process that creates .html, .docx or .pdf out of the source .Rmd file. This is what you then see in RStudio viewer for instance. So the output is not "inside" the .Rmd file. The .Rmd file just contains the code to make the output. If you want to see the output online, you have upload the .html knitted result somewhere. – jakub Oct 02 '16 at 08:46
  • @jakub Thanks. Will do the same – Shankar Pandala Oct 02 '16 at 09:14

2 Answers2

85

Instead of:

output: html_document

make it:

output: rmarkdown::github_document

(assuming you have the latest rmarkdown installed which you should if you're using RStudio — which I suspect you are — and keep it updated or update packages regularly).

It will create Exploring_one_variable.md and render the images as files.

When you browse to that markdown file, the images will render.

An alternative is to use:

output: 
  html_document:
    keep_md: true

and it will render to both Exploring_one_variable.md and Exploring_one_variable.html so you'll have the best of both worlds without the local github-esque preview that the former provides.

You can get fancier and put something like the following as the first code section in the Rmd:

```{r, echo = FALSE}
knitr::opts_chunk$set(
  fig.path = "README_figs/README-"
)
```

which will put the figures in a directory of your choosing.

You can see this in action here as the README.md was generated with knitr from the README.Rmd in the same directory.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 1
    Doing this messed my file, transforming him into a `.md` file. Now I don't have anymore my original `.Rmd` file. – igorkf Jun 21 '20 at 22:07
0

There is now output: github_document

jaksco
  • 423
  • 7
  • 18