How to write text inside a function in knitr

I am trying to comment some functions that have lots of line of code. So I would like to write some paragraphs inside the function.

Example:

```{r}
sample.fn <- function(x) {
x <- x+1
x <- x+2
#...
```

Here I would like to write some text. Maybe write some equations:

$$  
\begin{align}   
x &= x + 1\\  
\end{align*}  
$$  

And then continue with the function

```{r}
x <- x + 3
return(x)
}
```

Thanks

Upvotes: 2

Views: 217

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 145785

Turning my comment to an answer: I don't believe there's a way to break up an evaluated chunk, but you can create the illusion with some sleight-of-chunk. Include one chunk that is not printed (i.e., echo = FALSE) that includes your full function definition, and then include as many chunks as you want with eval = FALSE that repeat the code but with as many breaks in the chunk as you like.

Upvotes: 1

Related Questions