Code reuse non-OJS? #4367
-
There might be a way to do this and I am not seeing it, but I was wondering if there is a way that I could do a code-reuse the same way that you can with OJS objects but with Python objects? For example:
Or should I just go the standard route and define |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Are those code cells meant to be like so?
In this case, no, that's not supported and is unlikely going to be supported in the near-to-medium future. The fundamental reason is that we try to keep a pretty close relationship between .qmd and the .ipynb it can produce, and the cell in |
Beta Was this translation helpful? Give feedback.
-
For R chunks, a way to achieve this is to use code externalisation, i.e. the code chunks are in a separate R file, and all qmd files can refer to them. Example gist It's also possible to generate the external R file automatically from a qmd document using |
Beta Was this translation helpful? Give feedback.
For R chunks, a way to achieve this is to use code externalisation, i.e. the code chunks are in a separate R file, and all qmd files can refer to them. Example gist
It's also possible to generate the external R file automatically from a qmd document using
knitr::purl()
, so the process could be automated (file2.qmd
referring to chunks fromfile1.qmd
via an automatically generated R file, which could be done as a pre-render step, for instance. When doing this with several files, things could get a bit messy with chunk names (you'd have to keep a good convention to make them unique) and execution order.