0
votes

When knitting an Rmd to an md document, is there an option to put the R output in the same chunk as the code?

> knit.txt = 'Hello
+ ```{r}
+ 3+3
+ a <- 3+3
+ ```'

> library(knitr)

> out = knit(text=knit.txt, quiet=TRUE)

> cat(out)
Hello

```r
3+3
```

```
## [1] 6
```

```r
a <- 3+3
```

You can see knitr produces three chunks but intead I want one chunk look like this:

3+3
##6
a <- 3+3
1

1 Answers

2
votes

You want the chunk option collapse = TRUE

```{r, collapse = TRUE}
3+3
a <- 3 + 3
```