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

I am currently writing documentation for the R package hosted on GitHub . I use knitr along with R Markdown to write a README file. Clicking the Knit HTML button in RStudio creates the HTML code as I expected.

However, clicking README.rmd on GitHub leads to what you see at the bottom of the page, following the link above. For example, the topmost code snippet is declared in the README.rmd file as follows:

 ```{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 GitHub linking page. In addition, the results (for example, from plot() , head() ) are not visualized, although opts_chunk$set(..., include = TRUE) .

Has anyone encountered a similar problem and can I help me render the README document correctly, i.e. how does RStudio handle this on github?

+5
source share
2 answers

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

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

This will evaluate the global and chunk parameters specified in the .rmd source and create a .md that is formatted appropriately and which github can easily display.

+9
source

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

You can also configure devtools automatically for your package with devtools::use_readme_rmd() .

+1
source

Source: https://habr.com/ru/post/1204402/


All Articles