I have a chunk in an RMarkdown document that looks like this:
```{r, echo=-4}
a <- 1
b <- 2
x <- a + b
print(paste(c("`x` is equal to ", x), collapse=""))
```
When I knit this, it doesn't show the 4th expression, as expected and as documented here.
a <- 1
b <- 2
x <- a + b
## [1] "`x` is equal to 3"
However, if I add another line within the chunk, I have to update the echo
parameter or it hides the wrong expression:
```{r, echo=-4}
a <- 1
b <- 2
c <- 3
x <- a + b + c
print(paste(c("`x` is equal to ", x), collapse=""))
```
Output:
a <- 1
b <- 2
c <- 3
print(paste(c("`x' is equal to ", x), collapse=""))
## [1] "`x` is equal to 6"
Is there a programmatic way in an RMarkdown Chunk to specify that you don't want to echo the last expression in a chunk without manually counting the total number of lines?