如何在大块中间更改编织选项 [英] How to change knitr options mid chunk

查看:82
本文介绍了如何在大块中间更改编织选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改中间的块选项,而不必创建新的块.

Hi I would like to change chunk options, mid chunk, without having to create a new chunk..

运行以下代码,我希望获得两个截然不同的大小输出,但是由于某种原因,似乎并非如此.

running the following code I would expect to get two very different size outputs, but for some reason this does not seem to be the case.

第二个绘图也根本不绘图...(当您将其更改为plot(2:1000)时也可以绘图...但是无论哪种方式,第二个输出都与第一个相同. >.我在做什么错了?

Also the second plot doesn't plot at all...(it does when you change it to plot(2:1000)...but either way the second output is the same size as the first. both fig.width=7. What am I doing wrong?

请注意中间块"的重要性,原因是我想在运行函数以获取不同大小的不同输出时多次更改块选项.

Pls note the importance of 'mid chunk' the reason for this is that I would like to change the chunk options several times when running a function to get different outputs of different sizes.

```{r}
sessionInfo()

opts_chunk$set(fig.width=3)

plot(1:1000)

opts_chunk$set(fig.width=10)

plot(1:1000)

```

sessionInfo输出如下:

the sessionInfo output is as follows:

## R version 2.15.1 (2012-06-22)
## Platform: i386-pc-mingw32/i386 (32-bit)
## 
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252 
## [2] LC_CTYPE=English_United Kingdom.1252   
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C                           
## [5] LC_TIME=English_United Kingdom.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] knitr_0.7
## 
## loaded via a namespace (and not attached):
## [1] digest_0.5.2   evaluate_0.4.2 formatR_0.5    parser_0.0-16 
## [5] plyr_1.7.1     Rcpp_0.9.13    stringr_0.6    tools_2.15.1  

推荐答案

两个问题:当您希望同时保留两个数字时,请使用

Two questions: When you want both figures to be keep, use

```{r fig.keep='all'}

默认仅保留唯一的图(因为您的两个图相同,因此第二个图被删除;请参见编织图形手册以获取详细信息).

Default only keeps the unique plots (because your two plots are identical, the second one is removed; see the knitr graphics manual for details).

下一个块打开时,全局块选项将处于活动状态:

Global chunk options are active when the next chunk(s) open:

```{r}
opts_chunk$set(fig.width=10)
```


```{r}
opts_chunk$set(fig.width=2)
# Our figure is 10 wide, not 2
plot(1:1000)
```

```{r}
# Our figure is 2 wide, not 10
opts_chunk$set(fig.width=10)
plot(1:1000)
```

这篇关于如何在大块中间更改编织选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆