0

Is there a way to knit only certain chunks into a HTML document?

Say I'm doing analysis on 3 different cell markers, can I tell R to start knitting at the beginning of Marker1 and stop knitting at the end of Marker 1, then start knitting at Marker 2 etc to ultimately create 3 HTML files?

The only way I can think to do this is split my analysis into multiple Rscript files but I really don't want to do that.

dput(mtcars)

#Start knit1
#+
model1 <- lm(mpg ~ cyl, data = mtcars)
summary(model1)
#End knit1

#Start knit2
#+
model2 <- lm(mpg ~ hp, data = mtcars)
summary(model2)
#End knit2

#Start knit3
#+
model3 <- lm(mpg ~ disp, data = mtcars)
summary(model2)
#End knit3

Thank you for your help!

iastatecy
  • 67
  • 7
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 07 '21 at 20:17
  • A chunk can have an `eval=` argument, which can be literal or an R expression that returns true/false. With this and [rmarkdown parameters](https://rmarkdown.rstudio.com/lesson-6.html), you can determine a mechanism by which some chunks are not executed. Alternatively, you can use [`knitr::knit_exit()`](https://bookdown.org/yihui/rmarkdown-cookbook/knit-exit.html). – r2evans Jan 07 '21 at 20:37
  • Alternatively this would be helpful but less ideal: entering a page break somehow within the Rscript so when knitted, the HTML or PDF document will print each analysis at the beginning of a page. – iastatecy Jan 07 '21 at 20:49

0 Answers0