-
Notifications
You must be signed in to change notification settings - Fork 23
Add python support to quarto-authoring skill #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,16 @@ library(ggplot2) | |
| ``` | ||
| ```` | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| echo: false | ||
|
|
||
| # This code runs but is not shown | ||
| import pandas as pd | ||
| import matplotlib.pyplot as plt | ||
| ``` | ||
| ```` | ||
|
|
||
| Show fenced code block with attributes: | ||
|
|
||
| ````markdown | ||
|
|
@@ -96,6 +106,8 @@ Options for controlling figure output: | |
|
|
||
| ### Figure Example | ||
|
|
||
| R: | ||
|
|
||
|
Comment on lines
+109
to
+110
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than showing two examples of the same thing, I'd rather we diversify the examples to use languages in addition to R. In other words, in this case, we're trying to show the model the set of cell options that are relevant for figures. LLMs can generalize from one example showing the code cell options; we don't need two examples that contain identical options. That said, I do think it's helpful for there to be diversity in the examples, which also helps the model generalize. So I'd prefer if, in cases like this example, rather than adding a new identical example we were to simply rewrite some examples in other languages. We should prefer R and Python, but it'd be nice to have Julia or another language often used by Quarto authors in the examples. |
||
| ````markdown | ||
| ```{r} | ||
| #| label: fig-analysis | ||
|
|
@@ -111,8 +123,26 @@ ggplot(data, aes(x, y)) + | |
| ``` | ||
| ```` | ||
|
|
||
| Python: | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| label: fig-analysis | ||
| #| fig-cap: "Analysis results showing the relationship between variables." | ||
| #| fig-alt: "Scatter plot with trend line showing positive correlation." | ||
| #| fig-width: 10 | ||
| #| fig-height: 6 | ||
| #| fig-align: center | ||
|
|
||
| import seaborn as sns | ||
| sns.regplot(x=data["x"], y=data["y"]) | ||
| ``` | ||
| ```` | ||
|
|
||
| ### Multiple Figures | ||
|
|
||
| R: | ||
|
|
||
| ````markdown | ||
| ```{r} | ||
| #| label: fig-panels | ||
|
|
@@ -127,6 +157,25 @@ hist(y) | |
| ``` | ||
| ```` | ||
|
|
||
| Python: | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| label: fig-panels | ||
| #| fig-cap: "Multiple panel figure." | ||
| #| fig-subcap: | ||
| #| - "Distribution of X" | ||
| #| - "Distribution of Y" | ||
| #| layout-ncol: 2 | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| plt.hist(x) | ||
| plt.show() | ||
| plt.hist(y) | ||
| plt.show() | ||
| ``` | ||
| ```` | ||
|
|
||
| ## Table Options | ||
|
|
||
| Options for controlling table output: | ||
|
|
@@ -140,6 +189,8 @@ Options for controlling table output: | |
|
|
||
| ### Table Example | ||
|
|
||
| R: | ||
|
|
||
| ````markdown | ||
| ```{r} | ||
| #| label: tbl-summary | ||
|
|
@@ -149,6 +200,29 @@ knitr::kable(summary_data) | |
| ``` | ||
| ```` | ||
|
|
||
| Python (pandas — `output: asis` renders markdown table in all formats): | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| label: tbl-summary | ||
| #| tbl-cap: "Summary statistics by group." | ||
| #| output: asis | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Briefly,
Could we add one explainer subsection in this file, under "Execution Options", that defines |
||
|
|
||
| print(summary_df.to_markdown(index=False)) | ||
| ``` | ||
| ```` | ||
|
Comment on lines
+203
to
+213
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good example of a case where it is quite helpful to have an extra example in Python, because the additional example shows something new. |
||
|
|
||
| Python (pandas — plain `df` auto-displays as HTML table in HTML output): | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| label: tbl-summary | ||
| #| tbl-cap: "Summary statistics by group." | ||
|
|
||
| summary_df | ||
| ``` | ||
| ```` | ||
|
Comment on lines
+215
to
+224
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend removing this example, but keeping the comment about pandas data frames auto-displaying as HTML in HTML output (either above or below the asis-output example) |
||
|
|
||
| ## Caching and Freeze | ||
|
|
||
| Control caching of code cell results: | ||
|
|
@@ -161,6 +235,8 @@ Control caching of code cell results: | |
|
|
||
| ### Caching Example | ||
|
|
||
| R: | ||
|
|
||
| ````markdown | ||
| ```{r} | ||
| #| label: slow-computation | ||
|
|
@@ -171,6 +247,18 @@ result <- slow_function(data) | |
| ``` | ||
| ```` | ||
|
|
||
| Python: | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| label: slow-computation | ||
| #| cache: true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cell-level As written this example is silently inert: it will not cache, and it will teach the skill a pattern that does nothing, which is worse than omitting Python caching entirely. Suggest dropping the code example and replacing it with a short prose note pointing at https://quarto.org/docs/projects/code-execution.html#cache (use the |
||
|
|
||
| # This expensive computation is cached | ||
| result = slow_function(data) | ||
| ``` | ||
| ```` | ||
|
|
||
| ### Project-Level Freeze | ||
|
|
||
| In `_quarto.yml`: | ||
|
|
@@ -240,6 +328,8 @@ plot(1:10) | |
|
|
||
| Add annotations to explain code: | ||
|
|
||
| R: | ||
|
|
||
| ````markdown | ||
| ```{r} | ||
| #| code-annotations: hover | ||
|
|
@@ -255,6 +345,22 @@ mtcars |> # <1> | |
| 2. Filter to cars with MPG over 20 | ||
| 3. Select only the columns we need | ||
|
|
||
| Python: | ||
|
|
||
| ````markdown | ||
| ```{python} | ||
| #| code-annotations: hover | ||
|
|
||
| import pandas as pd # <1> | ||
| df = pd.read_csv("data.csv") # <2> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, but the example is self-inconsistent: it reads |
||
| result = df[df["mpg"] > 20][["mpg", "cyl"]] # <3> | ||
| ``` | ||
| ```` | ||
|
|
||
| 1. Import pandas for data manipulation | ||
| 2. Load the dataset from a CSV file | ||
| 3. Filter rows and select columns of interest | ||
|
|
||
| Annotation styles: `hover`, `select`, `below`, `beside`. | ||
|
|
||
| ## Filename Display | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues with the description rewrite.
First, "R (knitr) and Python (Jupyter) engines" is not quite accurate. Knitr runs any language registered as a knitr language engine (Python, Julia, Bash, SQL, Stan, and more), and jupyter runs any registered kernel (R via IRkernel, Julia via IJulia, Bash, and more). Pinning the description to two language/engine pairs paints Quarto as narrower than it is. There are three native engines (
knitr,jupyter,julia), and in 1.9 the julia engine was refactored to sit on top of the new engine-extension mechanism, so it is both a native engine and the reference implementation for third-party engine extensions. The skill is pinned to 1.9.36 (line 17), so leaving julia and engine extensions out is a dated inaccuracy. Quarto is language-agnostic anyway, so any enumeration of languages will bit-rot the next time a new kernel or engine ships. And since Quarto 1.9 ships engine extensions, the set of computing engines behind a code cell is no longer closed: in principle anything can end up there, so engines are the stable abstraction to describe in the skill.Second, the trigger wording. "Migrating R Markdown, bookdown, ..." narrows a key trigger, because users are far more likely to say "convert my old .Rmd" than "migrate my .Rmd", and the description is the main signal the LLM uses to pick this skill. Please keep "converting and migrating".
One more thing: the rewrite shortens the keyword surface ("code cell options, figure and table captions, cross-references, callout blocks (notes, warnings, tips), citations and bibliography" becomes "code cells, figures, tables, cross-references, callouts, citations"). Shorter descriptions match less reliably on keyword-rich queries, so the longer form was closer to what I would want.
Suggested rewording that keeps the enumerative surface, restores "converting", adds the missing
.ipynbtrigger, and refers to engines rather than languages: