3

I am knitting a R markdown and the output looks fine for now, except for the problem that for some reason the knitted html shows the dplyr::summarise output too. Even after turning off show messages and show warnings the output persists. Please note that when I run the code without knitting, the console doesn't show this output.

How can I suppress this from showing in the html?

library(tidyverse)

# Used in main code to summarize data 
## Summarize data 
DF_Summarize = DF%>% 
  group_by(Code) %>% 
  summarise(Count_2020 = n())

Output showing in html. Now these are the summarized values from the dataframe.

##  [1]   2 179   5  47   6  92  33   1   6   5   3  13   6  99   1   7   4   4 423
## [20]  53  11   7 110  35 101   6   2   7   3   2   1   2   1   7   4   1   3   6
## [39]   3   5   1   3   7  13   1  40   1   7   2   1   3  18   1   2  10   1   2
## [58]   1  40
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
  • 2
    This doesn't look output from the summarised code. Are you printing something else in the markdown file? – Ronak Shah Aug 06 '21 at 06:04
  • You are working with chunks, aren't? If so, have you tried the chunk option `results="hide"` or `eval=FALSE`? – Leonardo Hansa Aug 06 '21 at 06:05
  • @LeonardoHansa, yes I am working with chunks, will these settings still generate a `ggplotly` present in that chunk? – Ed_Gravy Aug 06 '21 at 06:11
  • 1
    Shouldn't output from `group_by` and `summarise` return a dataframe/tibble ? The output shown looks like a vector. – Ronak Shah Aug 06 '21 at 06:12
  • @RonakShah, yes you are right, the summarized data was stored in a `dataframe`. I don't really know from where this output in the knitted `html` is coming from, because running the code without knitting doesn't produced this sort of output in the console. Should I post my original code, it's a bit long though? – Ed_Gravy Aug 06 '21 at 06:15
  • No worries, I found the mistake in the code. `DF$Count_2020` was present in the chunk as a line so that was causing it. You were right in your first comment Shah g; thank you for pointing that out. – Ed_Gravy Aug 06 '21 at 06:18

1 Answers1

0

You can just use echo = FALSE in the knitr chunk label.

i.e.

```{r summarize, echo = FALSE}
## Summarize data 
DF_Summarize = DF%>% 
  group_by(Code) %>% 
  summarise(Count_2020 = n())
```

If you have other chunk output that you do want to display, just break up the chunks and use echo = FALSE in the one you want to hide, and leave echo = TRUE for the others.

Sam Rogers
  • 787
  • 1
  • 8
  • 19