简体   繁体   English

使用knitr和pandoc创建docx文件时,有没有办法隐藏图标?

[英]Is there a way to hide figure captions when using knitr and pandoc to create docx files?

I am using knitr and pandoc to write reports into word (we need to be able to circulate for comments using track changes etc). 我正在使用knitr和pandoc将报告写入单词(我们需要能够使用跟踪更改来传播评论等)。

It is working very well so far, but I have found that the plots are all coming out with captions at the bottom, and I don't want captions. 它到目前为止工作得非常好,但我发现这些情节都是底部带有字幕的,我不想要字幕。 While I could just delete them in the word doc, if I can stop them showing in the code it would be better. 虽然我可以在单词doc中删除它们,但如果我可以阻止它们在代码中显示它会更好。

So for the following code in markdown: 因此,对于markdown中的以下代码:

Test test test

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r fig.width=7, fig.height=6}
plot(cars)
```

I then run the following code in R: 然后我在R中运行以下代码:

library("knitr")

# Stackoverflow table test 1.html

knit2html("captiontest.rmd")

FILE <- "captiontest"

system(paste0("pandoc -o ", FILE, ".docx ", FILE, ".md"))

And the graph, in the word document, has the caption "plot of chunk unnamed-chunk-2" 而word文档中的图表标题为“chunk unnamed-chunk-2”

I know I can change this caption, eg {r fig.width=7, fig.height=6, fig.cap='hello'} , but I thought that fig.cap=NULL would make it hidden. 我知道我可以改变这个标题,例如{r fig.width=7, fig.height=6, fig.cap='hello'} ,但我认为fig.cap=NULL会让它隐藏起来。 Instead it seems to make the whole plot disappear. 相反,它似乎使整个情节消失。

Are plots required to have a caption - do I just have to go through each word doc and delete them manually? 情节是否需要有标题 - 我是否只需要浏览每个单词doc并手动删除它们? Or is there a way to hide them? 或者有办法隐藏它们吗?

Kind of a dirty trick, but: 有点肮脏的把戏,但是:

You can set fig.cap="" on the chunk in question: 你可以在有问题的块上设置fig.cap=""

Test test test

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r fig.width=7, fig.height=6, fig.cap=""}
plot(cars)
```

Or, you can set fig.cap="" for all chunks at once in an initializing chunk at the beginning of your Rmd document: 或者,您可以在Rmd文档开头的初始化块中一次为所有块设置fig.cap=""

Test test test

```{r options-chunk} 
opts_chunk$set(fig.cap="")
``` 

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r fig.width=7, fig.height=6}
plot(cars)
```

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM