knitr-style code reuse for Jupyter-based documents #10541
allefeld
started this conversation in
Feature Requests
Replies: 1 comment 5 replies
-
Thanks for the suggestion. Frankly, we're very unlikely to implement this, because it would make the jupyter execution through Quarto very incompatible with that of existing notebooks. This is a feature that specific kernels should implement themselves (some kind of jupyter magics, maybe?), and then Quarto's execution would inherit the behavior. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
I recently discovered the knitr feature of reusing code from a previous chunk in a later one, see "Embed one chunk in another chunk" – and I'm loving it. The same also works in Quarto
qmd
-files using R.My feature request is to implement the same or something similar for
qmd
-files using Jupyter kernels. That would have to happen before or during conversion ofqmd
intoquarto_ipynb
.Motivation:
This feature is very useful for literate programming.
For example, I often write code to analyse data from a number of participants. With code reuse, I can first develop the analysis code step-by-step in separate chunks, applied to the data of one participant, then pull the code from the different chunks together into a function and apply that function to the data of the other participants. This is from a
qmd
file using R to preprocess eyetracking data :and so on, over many chunks.
Then after all steps are complete, I can write:
knitr replaces the
<<label>>
references by the contents of the respective chunks, and executes and shows in the output the resulting code.Writing the code cumulatively like this is useful to give the output to a student to read, but also when refamiliarizing oneself with code after a pause.
Beta Was this translation helpful? Give feedback.
All reactions