I want my html file to show the code, but not the output of this chunk:
```{r echo=True, include=FALSE}
fun <- function(b)
{
for(a in b)
{print(a)
return(a * a)}
}
y <- fun(b)
```
When I run the code, i need the print to see the progress (it is quite a long function in reality).
But in the knitr file, I use the output in a further chunk, so I do not want to see it in this one (and there's no notion of progress, since the code has already been run).
This echo=True, include=FALSE
here does not work: the whole thing is hidden (which is the normal behavior of include=FALSE
).
What are the parameters I could use to hide the prints, but show my code?
This question is related to
r
knitr
r-markdown
For what it's worth.
```{r eval=FALSE}
The document will display the code by default but will prevent the code block from being executed, and thus will also not display any results.
For muting library("name_of_library")
codes, meanly just showing the codes, {r loadlib, echo=T, results='hide', message=F, warning=F}
is great. And imho a better way than library(package, warn.conflicts=F, quietly=T)
To hide warnings, you can also do
{r, warning=FALSE}
The results = 'hide'
option doesn't prevent other messages to be printed.
To hide them, the following options are useful:
{r, error=FALSE}
{r, warning=FALSE}
{r, message=FALSE}
In every case, the corresponding warning, error or message will be printed to the console instead.
For completely silencing the output, here what works for me
```{r error=FALSE, warning=FALSE, message=FALSE}
invisible({capture.output({
# Your code here
2 * 2
# etc etc
})})
```
The 5 measures used above are
error = FALSE
warning = FALSE
message = FALSE
invisible()
capture.output()
Source: Stackoverflow.com