Markdown conditionally run chunks

Hi all,

I am hoping to create a markdown script that can decide intelligently whether to run quarterly versions of scripts or monthly versions. To that end, I have different scripts that correspond to whether it should be quarterly or monthly.

My question to the group here is whether it is possible to have R decide on its own if it is a quarter or month end and then, based on that, run chunks selectively (i.e. it can turn eval = TRUE into eval = FALSE).

Has anyone ever attempted to do this before?


It looks like you can make a logical variable (or two) to pass to eval. Maybe based on the date or something in your case (i.e., however you figure out if it is the end of quarter/month :grinning:)?

I haven't tried it, but see the Stack Overflow answer here:

I think some of the info in this GitHub issue also looks relevant.


Interesting. So I'm giving that a shot, but it appears that it does still run the chunk even though the value comes back as false. I've screenshotted the basic details here.

Any thoughts on where this may have gone wrong?

Actually, I was wrong. If I knit the document, it appears to have worked. Thank you so much for the help! This is a much more elegant solution than the people who had written this same report before had come up with. Very excited!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.