[英]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.html的Readme.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.