Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub displays all code chunks from README.rmd (despite include=FALSE)

I am currently writing a documentation for an R package hosted on GitHub. I use knitr along with R Markdown to write the README file. Hitting the 'Knit HTML' button in RStudio produces an HTML like I would expect it.

However, pushing README.rmd to GitHub results in what you see in the lower page section when following the above link. For example, the topmost code chunk is declared as follows in the README.rmd file:

```{r global_options, include = FALSE}
library(knitr)
options(width = 120)
opts_chunk$set(fig.width = 12, fig.height = 8, fig.path = 'Figs/',
               include = TRUE, warning = FALSE, message = FALSE)
```

However, the include = FALSE statement in the first line of code is simply ignored in this case, and the piece of code that was supposed to be hidden is displayed on the referring GitHub page. In addition, results (e.g. from plot(), head()) are not visualized although opts_chunk$set(..., include = TRUE).

Did anyone encounter a similar problem and can me help me get my README document displayed correct, i.e. in the way RStudio would handle it, on GitHub?

like image 561
fdetsch Avatar asked Oct 10 '14 09:10

fdetsch


2 Answers

The readme file you are trying to publish on github should be a plain markdown document i.e., a .md file and not the raw .rmd. So first you knit the .rmd with knitr (within R) as follows:

knit(input="readme.rmd", output = "readme.md") #see ?knit for more options

That will evaluate the global and chunk options specified in the source .rmd and produce a .md that's formatted accordingly and which github can render readily.

like image 175
shekeine Avatar answered Oct 08 '22 20:10

shekeine


For more information on using an .Rmd to generate the .md see the Readme.Rmd section of http://r-pkgs.had.co.nz/release.html

You can also have devtools set up this automatically for your package using devtools::use_readme_rmd().

like image 23
Jim Avatar answered Oct 08 '22 20:10

Jim