Skip to content

Commit

Permalink
fix: missing empty line before list (#156)
Browse files Browse the repository at this point in the history
* fix: missing empty line before list

* ci: quarto automatic render

skip-checks: true

* chore: update freeze

* ci: quarto automatic render

skip-checks: true

---------

Co-authored-by: mcanouil <[email protected]>
  • Loading branch information
mcanouil and mcanouil authored Apr 25, 2024
1 parent 0c04830 commit 586848e
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 241 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"hash": "3437133035a6f4b5448d9e3f5637dcd4",
"hash": "bffcc121667dfc8202f299335ae2900f",
"result": {
"markdown": "---\ntitle: \"Quarto Q&A: How to have labels and captions for an unknown number of tables?\"\ndescription: |\n A small example of how to automatically have labels and captions for an unknown number of tables in Quarto, using `knitr` and R.\ndate: \"2023-03-05\"\ncategories: [Quarto, Q&A, R, knitr]\nimage: featured.png\nimage-alt: |\n Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.\n Tables are simply on top of each other after the item list.\n---\n\n\nI decided to start small blog posts with answers/solutions to questions I have seen and answered on [Twitter](https://twitter.com/), [Mastodon](https://joinmastodon.org/), and [Quarto](https://quarto.org/) GitHub [Issues](https://github.com/quarto-dev/quarto-cli/issues) & [Discussions](https://github.com/quarto-dev/quarto-cli/discussions).\n\n![](featured.png){fig-alt=\"Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables. Tables are simply on top of each other after the item list.\" fig-align=\"center\"}\n\n## The Question/Problem\n\n> Suppose, in a #QuartoPub document, using #rStats I have a list of length G, each item in this list is a flextable - I need to use flextable as opposed to kable, to allow for output to docx.\n> G is unknown apriori, but will be at least 1.\n>\n> Is there any way to create a sequence of tables with associated labels and captions that could be worked out dynamically/parsed? \n> Manually, this can be done really easily (creating new labels etc) and knowing when to stop, but is there a way of automating this?\n\n_Source: <https://mastodon.ie/@DToher/109915736491084825>_\n\n## The Answer/Solution\n\nThe trick is, within a code cell with `output: asis`, to use `knitr::knit_child()` to create code cells with `label`, caption (`tbl-cap`), or whatever option you might want or need.\n\n\n::: {.cell .panel-tabset}\n\n## Quarto Input\n\n````md\n---\nformat: html\n---\n\n```{r}\n#| include: false\nfor (ipkg in c(\"palmerpenguins\", \"gt\", \"dplyr\")) {\n if (!require(ipkg, character.only = TRUE)) {\n install.packages(ipkg)\n library(ipkg, character.only = TRUE)\n }\n}\n```\n\nBelow are tables of the first six rows of the Palmer penguins dataset by species:\n\n```{r}\n#| echo: false\n#| output: asis\ncat(\n sprintf(\n \"- `%s` (@tbl-%s)\",\n levels(penguins[[\"species\"]]),\n levels(penguins[[\"species\"]])\n ),\n sep = \"\\n\"\n)\n\nfor (ispecies in levels(penguins[[\"species\"]])) {\n tab <- penguins |>\n filter(species %in% ispecies) |>\n select(-species) |>\n head() |>\n gt() |>\n tab_header(title = ispecies)\n cat(sep = \"\\n\", knitr::knit_child(quiet = TRUE, text = c(\n \"```{r}\",\n \"#| echo: false\",\n sprintf(\"#| tbl-cap: %s\", ispecies),\n sprintf(\"#| label: tbl-%s\", ispecies),\n \"tab\",\n \"```\"\n )))\n}\n```\n````\n\n\n\n## Quarto Output\n\n![](featured.png){fig-alt='Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.\nTables are simply on top of each other after the item list.'}\n:::\n\n\n## References\n\nReferences:\n- <https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html>\n- <https://bookdown.org/yihui/rmarkdown-cookbook/knit-expand.html>\n- <https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html>\n\n## Examples\n\n- <https://github.com/quarto-dev/quarto-examples>\n",
"engine": "knitr",
"markdown": "---\ntitle: \"Quarto Q&A: How to have labels and captions for an unknown number of tables?\"\ndescription: |\n A small example of how to automatically have labels and captions for an unknown number of tables in Quarto, using `knitr` and R.\ndate: \"2023-03-05\"\ncategories: [Quarto, Q&A, R, knitr]\nimage: featured.png\nimage-alt: |\n Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.\n Tables are simply on top of each other after the item list.\n---\n\n\n\nI decided to start small blog posts with answers/solutions to questions I have seen and answered on [Twitter](https://twitter.com/), [Mastodon](https://joinmastodon.org/), and [Quarto](https://quarto.org/) GitHub [Issues](https://github.com/quarto-dev/quarto-cli/issues) & [Discussions](https://github.com/quarto-dev/quarto-cli/discussions).\n\n![](featured.png){fig-alt=\"Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables. Tables are simply on top of each other after the item list.\" fig-align=\"center\"}\n\n## The Question/Problem\n\n> Suppose, in a #QuartoPub document, using #rStats I have a list of length G, each item in this list is a flextable - I need to use flextable as opposed to kable, to allow for output to docx.\n> G is unknown apriori, but will be at least 1.\n>\n> Is there any way to create a sequence of tables with associated labels and captions that could be worked out dynamically/parsed? \n> Manually, this can be done really easily (creating new labels etc) and knowing when to stop, but is there a way of automating this?\n\n_Source: <https://mastodon.ie/@DToher/109915736491084825>_\n\n## The Answer/Solution\n\nThe trick is, within a code cell with `output: asis`, to use `knitr::knit_child()` to create code cells with `label`, caption (`tbl-cap`), or whatever option you might want or need.\n\n\n\n::: {.cell .panel-tabset}\n\n## Quarto Input\n\n````md\n---\nformat: html\n---\n\n```{r}\n#| include: false\nfor (ipkg in c(\"palmerpenguins\", \"gt\", \"dplyr\")) {\n if (!require(ipkg, character.only = TRUE)) {\n install.packages(ipkg)\n library(ipkg, character.only = TRUE)\n }\n}\n```\n\nBelow are tables of the first six rows of the Palmer penguins dataset by species:\n\n```{r}\n#| echo: false\n#| output: asis\ncat(\n sprintf(\n \"- `%s` (@tbl-%s)\",\n levels(penguins[[\"species\"]]),\n levels(penguins[[\"species\"]])\n ),\n sep = \"\\n\"\n)\n\nfor (ispecies in levels(penguins[[\"species\"]])) {\n tab <- penguins |>\n filter(species %in% ispecies) |>\n select(-species) |>\n head() |>\n gt() |>\n tab_header(title = ispecies)\n cat(sep = \"\\n\", knitr::knit_child(quiet = TRUE, text = c(\n \"```{r}\",\n \"#| echo: false\",\n sprintf(\"#| tbl-cap: %s\", ispecies),\n sprintf(\"#| label: tbl-%s\", ispecies),\n \"tab\",\n \"```\"\n )))\n}\n```\n````\n\n\n\n## Quarto Output\n\n![](featured.png){fig-alt='Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.\nTables are simply on top of each other after the item list.'}\n:::\n\n\n\n## References\n\nReferences:\n\n- <https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html>\n- <https://bookdown.org/yihui/rmarkdown-cookbook/knit-expand.html>\n- <https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html>\n\n## Examples\n\n- <https://github.com/quarto-dev/quarto-examples>\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
Expand Down
2 changes: 1 addition & 1 deletion _freeze/site_libs/quarto-listing/list.min.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions _site/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.27">
<meta name="generator" content="quarto-1.5.31">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down Expand Up @@ -245,10 +245,10 @@ <h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-list

<div class="quarto-listing quarto-listing-container-default" id="listing-listing">
<div class="list quarto-listing-default">
<div class="quarto-post image-right" data-index="0" data-categories="Quarto,Q&amp;A,JavaScript,theme,dark mode,light mode" data-listing-date-sort="1685404800000" data-listing-file-modified-sort="1711972853307" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="392">
<div class="quarto-post image-right" data-index="0" data-categories="Quarto,Q&amp;A,JavaScript,theme,dark mode,light mode" data-listing-date-sort="1685404800000" data-listing-file-modified-sort="1714041854894" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="392">
<div class="thumbnail">
<p><a href="./posts/2023-05-30-quarto-light-dark/index.html" class="no-external"></a></p><a href="./posts/2023-05-30-quarto-light-dark/index.html" class="no-external">
<p><img src="./posts/2023-05-30-quarto-light-dark/featured.gif" class="thumbnail-image" alt="Animated GIF showing a ggplot2 figure switching from light to dark on theme toggle switch.
<p><img loading="lazy" src="./posts/2023-05-30-quarto-light-dark/featured.gif" class="thumbnail-image" alt="Animated GIF showing a ggplot2 figure switching from light to dark on theme toggle switch.
"></p>
</a><p><a href="./posts/2023-05-30-quarto-light-dark/index.html" class="no-external"></a></p>
</div>
Expand Down Expand Up @@ -294,10 +294,10 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="1" data-categories="Quarto,Q&amp;A,Docker" data-listing-date-sort="1683417600000" data-listing-file-modified-sort="1711972853295" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="10" data-listing-word-count-sort="1860">
<div class="quarto-post image-right" data-index="1" data-categories="Quarto,Q&amp;A,Docker" data-listing-date-sort="1683417600000" data-listing-file-modified-sort="1714041854882" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="10" data-listing-word-count-sort="1860">
<div class="thumbnail">
<p><a href="./posts/2023-05-07-quarto-docker/index.html" class="no-external"></a></p><a href="./posts/2023-05-07-quarto-docker/index.html" class="no-external">
<p><img src="./posts/2023-05-07-quarto-docker/featured.png" class="thumbnail-image" alt="Docker logo with a whale and containers on top of it, and Quarto logo with text inside the whale.
<p><img loading="lazy" src="./posts/2023-05-07-quarto-docker/featured.png" class="thumbnail-image" alt="Docker logo with a whale and containers on top of it, and Quarto logo with text inside the whale.
"></p>
</a><p><a href="./posts/2023-05-07-quarto-docker/index.html" class="no-external"></a></p>
</div>
Expand Down Expand Up @@ -334,10 +334,10 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="2" data-categories="Quarto,Q&amp;A,MathJax,LaTeX" data-listing-date-sort="1678579200000" data-listing-file-modified-sort="1711972853295" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="212">
<div class="quarto-post image-right" data-index="2" data-categories="Quarto,Q&amp;A,MathJax,LaTeX" data-listing-date-sort="1678579200000" data-listing-file-modified-sort="1714041854882" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="212">
<div class="thumbnail">
<p><a href="./posts/2023-03-12-quarto-mathjax-packages/index.html" class="no-external"></a></p><a href="./posts/2023-03-12-quarto-mathjax-packages/index.html" class="no-external">
<p><img src="./posts/2023-03-12-quarto-mathjax-packages/featured.png" class="thumbnail-image" alt="Quarto logo and text in the center of the image. Below, MathJax logo and text.
<p><img loading="lazy" src="./posts/2023-03-12-quarto-mathjax-packages/featured.png" class="thumbnail-image" alt="Quarto logo and text in the center of the image. Below, MathJax logo and text.
"></p>
</a><p><a href="./posts/2023-03-12-quarto-mathjax-packages/index.html" class="no-external"></a></p>
</div>
Expand Down Expand Up @@ -377,10 +377,10 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="3" data-categories="Quarto,Q&amp;A,R,knitr" data-listing-date-sort="1677974400000" data-listing-file-modified-sort="1711972853295" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="310">
<div class="quarto-post image-right" data-index="3" data-categories="Quarto,Q&amp;A,R,knitr" data-listing-date-sort="1677974400000" data-listing-file-modified-sort="1714041854878" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="310">
<div class="thumbnail">
<p><a href="./posts/2023-03-05-quarto-auto-table-crossref/index.html" class="no-external"></a></p><a href="./posts/2023-03-05-quarto-auto-table-crossref/index.html" class="no-external">
<p><img src="./posts/2023-03-05-quarto-auto-table-crossref/featured.png" class="thumbnail-image" alt="Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.
<p><img loading="lazy" src="./posts/2023-03-05-quarto-auto-table-crossref/featured.png" class="thumbnail-image" alt="Screenshot of an html rendered by Quarto. it starts with a sentence saying below are several tables by species of penguins, followed by an item list showing the species and their respective cross-reference to the tables.
Tables are simply on top of each other after the item list.
"></p>
</a><p><a href="./posts/2023-03-05-quarto-auto-table-crossref/index.html" class="no-external"></a></p>
Expand Down Expand Up @@ -421,10 +421,10 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="4" data-categories="R,blogdown,rmarkdown,HUGO,Website" data-listing-date-sort="1620259200000" data-listing-file-modified-sort="1711972853295" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="16" data-listing-word-count-sort="3098">
<div class="quarto-post image-right" data-index="4" data-categories="R,blogdown,rmarkdown,HUGO,Website" data-listing-date-sort="1620259200000" data-listing-file-modified-sort="1714041854878" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="16" data-listing-word-count-sort="3098">
<div class="thumbnail">
<p><a href="./posts/2021-05-06-floating-toc-in-blogdown/index.html" class="no-external"></a></p><a href="./posts/2021-05-06-floating-toc-in-blogdown/index.html" class="no-external">
<p><img src="./posts/2021-05-06-floating-toc-in-blogdown/featured.png" class="thumbnail-image" alt="Screenshot of the `blogdown` blog post &amp;#039;Add a Floating Table of Contents in `blogdown`' showing a table of content on the right.
<p><img loading="lazy" src="./posts/2021-05-06-floating-toc-in-blogdown/featured.png" class="thumbnail-image" alt="Screenshot of the `blogdown` blog post &amp;#039;Add a Floating Table of Contents in `blogdown`' showing a table of content on the right.
"></p>
</a><p><a href="./posts/2021-05-06-floating-toc-in-blogdown/index.html" class="no-external"></a></p>
</div>
Expand Down Expand Up @@ -467,10 +467,10 @@ <h3 class="no-anchor listing-title">
</a>
</div>
</div>
<div class="quarto-post image-right" data-index="5" data-categories="R,Visualisation,ggplot2,gganimate,Fun" data-listing-date-sort="1588723200000" data-listing-file-modified-sort="1711972853275" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="29" data-listing-word-count-sort="5627">
<div class="quarto-post image-right" data-index="5" data-categories="R,Visualisation,ggplot2,gganimate,Fun" data-listing-date-sort="1588723200000" data-listing-file-modified-sort="1714041854858" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="29" data-listing-word-count-sort="5627">
<div class="thumbnail">
<p><a href="./posts/2020-05-06-ggpacman/index.html" class="no-external"></a></p><a href="./posts/2020-05-06-ggpacman/index.html" class="no-external">
<p><img src="./posts/2020-05-06-ggpacman/featured.png" class="thumbnail-image" alt="`ggpacman` hexagonal logo representing a red ghost from the game Pac-Man on a black background with a blue border and `ggpacman` written in yellow below the ghost.
<p><img loading="lazy" src="./posts/2020-05-06-ggpacman/featured.png" class="thumbnail-image" alt="`ggpacman` hexagonal logo representing a red ghost from the game Pac-Man on a black background with a blue border and `ggpacman` written in yellow below the ghost.
"></p>
</a><p><a href="./posts/2020-05-06-ggpacman/index.html" class="no-external"></a></p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion _site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.27">
<meta name="generator" content="quarto-1.5.31">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down
26 changes: 13 additions & 13 deletions _site/listings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
[
{
"listing": "/blog.html",
"items": [
"/posts/2023-05-30-quarto-light-dark/index.html",
"/posts/2023-05-07-quarto-docker/index.html",
"/posts/2023-03-12-quarto-mathjax-packages/index.html",
"/posts/2023-03-05-quarto-auto-table-crossref/index.html",
"/posts/2021-05-06-floating-toc-in-blogdown/index.html",
"/posts/2020-05-06-ggpacman/index.html"
]
},
{
"listing": "/talks.html",
"items": [
Expand All @@ -23,11 +12,22 @@
]
},
{
"listing": "/publications.html",
"listing": "/projects.html",
"items": []
},
{
"listing": "/projects.html",
"listing": "/publications.html",
"items": []
},
{
"listing": "/blog.html",
"items": [
"/posts/2023-05-30-quarto-light-dark/index.html",
"/posts/2023-05-07-quarto-docker/index.html",
"/posts/2023-03-12-quarto-mathjax-packages/index.html",
"/posts/2023-03-05-quarto-auto-table-crossref/index.html",
"/posts/2021-05-06-floating-toc-in-blogdown/index.html",
"/posts/2020-05-06-ggpacman/index.html"
]
}
]
6 changes: 3 additions & 3 deletions _site/posts/2020-05-06-ggpacman/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.27">
<meta name="generator" content="quarto-1.5.31">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Mickaël CANOUIL">
<meta name="description" content="The story of ggpacman. Or how to build a useless but fun R package to make a GIF of the game Pac-Man.">
Expand Down Expand Up @@ -32,7 +32,7 @@
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
Expand Down Expand Up @@ -2043,7 +2043,7 @@ <h1 class="title">A <code>ggplot2</code> and <code>gganimate</code> Version of P
"$1<sup style='font-size:0.5em;font-style:italic;'>$2</sup>"
);
});
</script><script>var lightboxQuarto = GLightbox({"openEffect":"zoom","closeEffect":"zoom","descPosition":"bottom","loop":false,"selector":".lightbox"});
</script><script>var lightboxQuarto = GLightbox({"selector":".lightbox","openEffect":"zoom","loop":false,"descPosition":"bottom","closeEffect":"zoom"});
window.onload = () => {
lightboxQuarto.on('slide_before_load', (data) => {
const { slideIndex, slideNode, slideConfig, player, trigger } = data;
Expand Down
Loading

0 comments on commit 586848e

Please sign in to comment.