I would like to conditionally execute code and render/emit markdown based on a conditional. I don't know how to make a complete self-contained regex in this case, so I will have to resort to pseudocode. I am using the spin format for rmarkdown in .R files rather than traditional rmarkdown syntax. I think the following pseudocode will describe what I want to do:
#+ computeConditional conditional_flag <- sample(c(TRUE, FALSE), 1) #+ eval=conditional_flag #' Flag was true x <- 1 #+ eval= ! conditional_flag #' Flag was false x <- 2
I know this doesn't work because markdown isn't part of the
#+ code section that gets defined, but the intent is that, if conditional_flag is true, I want it to print markdown that says the flag is true and to execute the code that is near there when the flag is true. If the flag is false, I want it to instead print the markdown saying it was false and execute that branch of code. I think I might be able to do this if I wrap the markdown in a
cat() statement, but I am wondering if I am missing a simpler construct that does what I want.