简体   繁体   English

GitHub显示来自README.rmd的所有代码块(尽管include = FALSE)

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

I am currently writing a documentation for an R package hosted on GitHub . 我目前正在为GitHub上托管R包编写文档。 I use knitr along with R Markdown to write the README file. 我使用knitr和R Markdown编写README文件。 Hitting the 'Knit HTML' button in RStudio produces an HTML like I would expect it. 点击RStudio中的“Knit HTML”按钮会产生一个像我期望的那样的HTML。

However, pushing README.rmd to GitHub results in what you see in the lower page section when following the above link. 但是,将README.rmd推送到GitHub会导致您在遵循上述链接时在下页部分中看到的内容。 For example, the topmost code chunk is declared as follows in the README.rmd file: 例如,最顶层的代码块在README.rmd文件中声明如下:

```{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. 但是,在这种情况下,第一行代码中的include = FALSE语句被忽略,并且应该隐藏的代码段显示在引用的GitHub页面上。 In addition, results (eg from plot() , head() ) are not visualized although opts_chunk$set(..., include = TRUE) . 此外,虽然opts_chunk$set(..., include = TRUE) ,但结果(例如来自plot()head() )的结果不可见。

Did anyone encounter a similar problem and can me help me get my README document displayed correct, ie in the way RStudio would handle it, on GitHub? 有没有人遇到类似的问题,我可以帮助我在GitHub上显示正确的README文档,即RStudio处理它的方式吗?

The readme file you are trying to publish on github should be a plain markdown document ie, a .md file and not the raw .rmd . 您尝试在github上发布的自述文件应该是简单的降价文档,即.md文件而不是原始.rmd So first you knit the .rmd with knitr (within R) as follows: 首先,你使用knitr(在R中)编织.rmd ,如下所示:

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. 这将评估源.rmd指定的全局和块选项,并生成相应格式化的.md以及哪个github可以轻松呈现。

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 有关使用.Rmd生成.md更多信息,请参阅http://r-pkgs.had.co.nz/release.htmlReadme.Rmd部分。

You can also have devtools set up this automatically for your package using devtools::use_readme_rmd() . 您也可以使用devtools::use_readme_rmd()自动为您的软件包设置devtools::use_readme_rmd()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Readme.Rmd导致Rstudio的github推送失败 - Readme.Rmd causes push failure to github from Rstudio 如何从 R 包的 README.Rmd 生成 README.md? - How to generate README.md from README.Rmd for R package? RStudio README.Rmd 和 README.md 都应该使用 'git commit --no-verify' 来覆盖这个检查 - RStudio README.Rmd and README.md should be both staged use 'git commit --no-verify' to override this check 如何添加预提交 git 钩子以检查 README.Rmd 和 index.Rmd 是否已编织? - How to add pre-commit git hooks to check that README.Rmd and index.Rmd have been knitted? 是否可以在github上放置R代码的自述文件,以显示输出? - Is it possible to put a readme file for R code on github, that displays output? 如何防止数据库连接代码块在 Rmd 中评估? - How to prevent db connection code chunks from evaluating in Rmd? 在顶级找到的非标准文件/目录:'README.Rmd'即使在实施建议的解决方案后仍然存在 - Non-standard file/directory found at top level: 'README.Rmd' persists even after implementing suggested solutions 从Rmd文档一次执行所有R块 - execute all R chunks at once from an Rmd document 从 R 脚本执行外部 Rmd 文件的所有 R 块 - Execute all R chunks of an external Rmd file from an R script 重用包含使用knitr .Rmd绘图的块 - reusing chunks that include plotting with knitr .Rmd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM