Skip to content
R for the Rest of Us Logo

How to conditionally execute code chunks in Quarto

Ever had a Quarto document where some code works perfectly in HTML but looks awful in Word (or vice versa)? I just ran into this problem with tables -{gt} tables look great in HTML but not so hot in Word, while {flextable} works beautifully in Word format.

In this quick video, I show you a neat trick for conditionally executing code in Quarto. This is super handy when you're creating documents that need to be exported to multiple formats. No more manually commenting out code or creating separate documents!

Sign up for the newsletter

Get blog posts like this delivered straight to your inbox.

Let us know what you think by adding a comment below.

You need to be signed-in to comment on this post. Login.

David Keyes
By David Keyes
June 5, 2025

Sign up for the newsletter

R tips and tricks straight to your inbox.