0

Is there a way to skip a set of code lines in R Markdown (knitr) given a condition?

If some condition is reached, I want to skip a set of lines (e.g, drop lines 60-100 if something is TRUE) including code (´´´< >´´´) and text (text). Or maybe something like a GOTO.

user2554330
  • 37,248
  • 4
  • 43
  • 90
RhoAct
  • 1
  • I'm not sure if its appropriate to tag this with 'markdown' in this context of "R Markdown" in specific. – cellepo Nov 01 '18 at 23:53
  • I'm not sure if this question is overly-broad, or a duplicate, along the lines of "R Markdown conditional statement/block". – cellepo Nov 01 '18 at 23:54
  • See https://yihui.name/knitr/options/, specifically "Code Evaluation" and "Text Results". – r2evans Nov 01 '18 at 23:56
  • More the point, the argument provided to `eval=` can be numeric, and that numeric vector can be conditioned on something else in the R environment. – r2evans Nov 02 '18 at 00:31
  • This also may be helpful for conditionally executing code using a `param` in the YAML header: https://stackoverflow.com/questions/39550732/is-there-a-way-to-have-conditional-markdown-chunk-execution-in-rmarkdown – mysteRious Nov 02 '18 at 00:54
  • Yeah, I can switch the given a condition, but imagine two chunks for whose there's text between, then if for both, the code won’t be runed but the text stills apearing. – RhoAct Nov 03 '18 at 00:19
  • I want a way to skip the code and also the *text*. – RhoAct Nov 03 '18 at 00:21
  • Could you put lines 60-100 in a separate file and evaluate that file as a child of the main document? – Russ Hyde Nov 06 '18 at 12:32

0 Answers0