Way to disable error output

21 views
Skip to first unread message

Kevin

unread,
Feb 4, 2013, 1:56:18 PM2/4/13
to ggp...@googlegroups.com
For example, I am documenting a process with Knitr and would like to disable the output of

# stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust ## this.

when using 
hist <- ggplot(data, aes(x=BCTransformedAS))

hist + geom_histogram(aes(y=..density..), colour="black", fill="white",bin = NULL) + geom_density(alpha=.2, fill="#FF6666")
 
I like the auto binning and I don't know a better way to specify that same binning other than this:
range <- max(BCTransformedAS) - max(BCTransformedAS)
hist <- ggplot(data, aes(x=range/30))

Ben Bolker

unread,
Feb 4, 2013, 1:58:42 PM2/4/13
to ggp...@googlegroups.com
I think you want message=FALSE in the chunk options.


Kevin

unread,
Feb 4, 2013, 2:46:54 PM2/4/13
to ggp...@googlegroups.com
I tried to set it globally by placing this in my first chunk:

```{r opts_chunk$set(message=FALSE,comment=NA, fig.width=8, fig.height=10)}

but it's not working. Any advice?

Kevin

unread,
Feb 4, 2013, 2:52:27 PM2/4/13
to ggp...@googlegroups.com
Sorry, I figured it out:

```{r set-options, echo=FALSE, cache=FALSE}
options(width=80)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = FALSE, size="small")
```
Thanks for the help

Brian Diggs

unread,
Feb 4, 2013, 3:12:15 PM2/4/13
to Kevin, ggplot2
On 2/4/2013 11:46 AM, Kevin wrote:
> I tried to set it globally by placing this in my first chunk:
>
> ```{r opts_chunk$set(message=FALSE,comment=NA, fig.width=8, fig.height=10)}
>
> but it's not working. Any advice?

I don't use knitr markdown that much, but I didn't think that would be
how to set global options. Should it be

```{r}
opts_chunk$set(message=FALSE,comment=NA, fig.width=8, fig.height=10)
```

or if you just want to set it for a single chunk

```{r message=FALSE}
...

As a final alternative, if you want to get rid of the message from just
that one line (not the whole chunk and not the whole document, with the
idea that other messages may be relevant), you could wrap the plotting
call itself: (Note that you have to wrap the printing, since that is
when the message is generated; otherwise the printing is done by the
default return which is outside the suppressMessages).

suppressMessages(print(hist + geom_histogram(aes(y=..density..),
colour="black",
fill="white",bin = NULL) + geom_density(alpha=.2, fill="#FF6666")))

> On Monday, February 4, 2013 10:58:42 AM UTC-8, Ben Bolker wrote:
>>
>> On 13-02-04 01:56 PM, Kevin wrote:
>>> For example, I am documenting a process with Knitr and would like to
>>> disable the output of
>>>
>>> # stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
>>> ## this.
>>>
>>
>>> when using
>>> hist <- ggplot(data, aes(x=BCTransformedAS))
>>>
>>> hist + geom_histogram(aes(y=..density..), colour="black",
>>> fill="white",bin = NULL) + geom_density(alpha=.2, fill="#FF6666")
>>>
>>> I like the auto binning and I don't know a better way to specify that
>>> same binning other than this:
>>> range <- max(BCTransformedAS) - max(BCTransformedAS)
>>> hist <- ggplot(data, aes(x=range/30))
>>
>> I think you want message=FALSE in the chunk options.
>>
>>
>>
>


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
Reply all
Reply to author
Forward
0 new messages