quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
280 stars 19 forks source link

How to run included .qmds interactively? #411

Open cderv opened 2 months ago

cderv commented 2 months ago

Description

Hi, we have a Quarto project where we use includes to make sure all chapters run some shared code. So basically at the beginning of several files we have something like:

{{< include _startup_code.qmd >}}

This works just fine when you render it with quarto render myproject, but to try things out interactively, it's a bit inconvenient. We need to run the code _startup_code.qmd before keep working on the chapter, and there does not seem to be a shortcut to do it (in vscode with the quarto extension installed and running the code in an ipython kernel), so basically we would need to manually open the file and run the code and then go back to the chapter to try things out.

Any ideas how to do this?, any easy way to instruct vscode to do it, and sort-of, shift-enter our way to automagically run all the code in the included file? Any ideas are greatly appreciated.

Note: perhaps we are abusing the includes functionality to avoid repeating ourselves too much and keep this relatively small project maintainable. So, sorry for that. Just to say that for larger/more complex projects we would use other orchestration tools (e.g. targets in R, or prefect, dvc, ploomber for python projects) and probably would not rely on includes this way.

Originally posted by @edalfon in https://github.com/quarto-dev/quarto-cli/discussions/7872

cderv commented 2 months ago

From @cscheid https://github.com/quarto-dev/quarto-cli/discussions/7872#discussioncomment-7821540

It's a valid request. One possibility would be for VS Code and RStudio to detect include shortcodes, and interpret the "execute code cell" to mean "expand all includes and execute all resulting cells". It's a bit of work for us to set it up, but I think it's the right thing to do.