<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Erwin Lares</title>
<link>https://erwinlares.com/posts/</link>
<atom:link href="https://erwinlares.com/posts/index.xml" rel="self" type="application/rss+xml"/>
<description>Linguist, data scientist, potter, aikidoka</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Wed, 07 Oct 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>From the Notebook to the Cluster Workshop Series</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-10-07-from-the-notebook-to-the-cluster-workshop-series/</link>
  <description><![CDATA[ 




<section id="roadmap" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="roadmap"><span class="header-section-number">1</span> Roadmap</h2>
<p>Each session picks up where the last one left off, following one research project through its evolution:</p>
<pre class="text"><code>Local analysis
      │
      ▼
toolero    →   Build a reproducible project
      │
      ▼
containr   →   Encapsulate that project into a portable container
      │
      ▼
submitr    →   Run that container on CHTC</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-10-07-from-the-notebook-to-the-cluster-workshop-series/n2c-workshop-logo.png" class="img-fluid figure-img"></p>
<figcaption>Hex sticker for the workshop series</figcaption>
</figure>
</div>
<p>You will see this same project – a real, if modest, analysis – go from a folder of scripts on a laptop, to a well-organized and documented R project, to a container that runs identically on any Docker-compatible machine, to a job executing on CHTC and returning results. Each session solves a genuine problem that shows up somewhere in that arc, and each one hands you something you can keep using afterward.</p>
</section>
<section id="the-three-sessions" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="the-three-sessions"><span class="header-section-number">2</span> The three sessions</h2>
<p>All three sessions run from 2:00 to 4:00 PM in CS 3139 (Computer Sciences Building), in person. You are welcome to attend all three in sequence, or to attend only the one that addresses the problem you have right now – more on how that works below.</p>
<section id="part-1-starting-clean-reproducible-r-projects-with-toolero" class="level3" data-number="2.1">
<h3 data-number="2.1" class="anchored" data-anchor-id="part-1-starting-clean-reproducible-r-projects-with-toolero"><span class="header-section-number">2.1</span> Part 1 – Starting Clean: Reproducible R Projects with <code>toolero</code></h3>
<p><strong>Wednesday, October 7 | from 2:00 — 4:00pm | CS 3139</strong></p>
<p>The starting point is the mess nearly every research project accumulates: scripts that only run in a particular order, dependencies nobody wrote down, a folder structure that made sense six months ago and no longer does. This session works through that mess directly, then introduces <code>toolero</code> to resolve it – reproducible project scaffolding, dependency management, and documentation practices that turn a personal working style into something someone else (including future you) can pick up and run. You will leave with <code>minimal-project</code>, a well-organized, reproducible R project that becomes the shared artifact for the rest of the series.</p>
</section>
<section id="part-2-portable-research-containerizing-r-projects-with-containr" class="level3" data-number="2.2">
<h3 data-number="2.2" class="anchored" data-anchor-id="part-2-portable-research-containerizing-r-projects-with-containr"><span class="header-section-number">2.2</span> Part 2 – Portable Research: Containerizing R Projects with <code>containr</code></h3>
<p><strong>Wednesday, October 14 | from 2:00 — 4:00pm | CS 3139</strong></p>
<p>A reproducible project on your laptop is still tied to your laptop. This session asks why <code>renv</code> alone is not enough to guarantee that an analysis runs the same way somewhere else, and introduces containers as the answer. Using <code>containr</code>, you will build a Dockerfile, build and run an image locally, and publish that image to a container registry. You will leave with a published container image for <code>minimal-project</code> that runs identically on any Docker-compatible machine.</p>
</section>
<section id="part-3-scaling-out-running-containerized-r-projects-on-chtc-with-submitr" class="level3" data-number="2.3">
<h3 data-number="2.3" class="anchored" data-anchor-id="part-3-scaling-out-running-containerized-r-projects-on-chtc-with-submitr"><span class="header-section-number">2.3</span> Part 3 – Scaling Out: Running Containerized R Projects on CHTC with <code>submitr</code></h3>
<p><strong>Thursday, October 22 | from 2:00 — 4:000pm | CS 3139</strong></p>
<p>A portable container is ready to run anywhere – including, at last, on CHTC. This session covers what a containerized project needs to run as an HTCondor job: preparing and uploading the required assets, submitting the job with <code>submitr</code>, and retrieving results. You will leave with a working submission file, executable, and a completed CHTC job for <code>minimal-project</code>, along with the workflow to do the same for your own research.</p>
</section>
</section>
<section id="come-to-one-come-to-all" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="come-to-one-come-to-all"><span class="header-section-number">3</span> Come to one, come to all</h2>
<p>The series tells one continuous story, but you do not need to attend every session to get value out of one. Each session works toward a shared hands-on task, and if you do not finish yours in the time available, I will have a completed version of that session’s artifact ready so you leave with something real either way:</p>
<ul>
<li><strong><code>toolero</code>:</strong> a finished <code>minimal-project.qmd</code> and its sample data, <code>data/penguins.csv</code></li>
<li><strong><code>containr</code>:</strong> a finished Dockerfile, a built image, and that image published to a container registry</li>
<li><strong><code>submitr</code>:</strong> a finished <code>.sub</code> submission file, a <code>.sh</code> executable file, a submitted job, and its results</li>
</ul>
<p>That means if you can only make it to the <code>containr</code> session, you will start from a working reproducible project (yours if you attended Part 1, mine if you did not) rather than getting stuck before the session’s real content even begins.</p>
</section>
<section id="who-this-is-for" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="who-this-is-for"><span class="header-section-number">4</span> Who this is for</h2>
<p>This series is aimed at researchers on campus who already write R code comfortably and intend to eventually run work on CHTC, but who have little or no experience with <code>renv</code>, containers, Docker, HTCondor, or CHTC workflows themselves. If that describes where you are, you are the intended audience – this is deliberately not a series for people who already have a container-to-cluster pipeline working.</p>
</section>
<section id="what-to-bring" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="what-to-bring"><span class="header-section-number">5</span> What to bring</h2>
<ul>
<li>A laptop</li>
<li>R and RStudio installed (<a href="https://rstudio-education.github.io/hopr/starting.html">here’s how to install them</a>)</li>
<li>A UW-Madison GitLab account (<a href="https://kb.wisc.edu/shared-tools/page.php?id=121442">learn more about UW-Madison’s GitLab instance</a>)</li>
<li>An SSH key or Personal Access Token already created for that account (learn how to create an <a href="https://docs.gitlab.com/user/ssh/">SSH key here</a> and/or a <a href="https://docs.gitlab.com/user/profile/personal_access_tokens/">PAT here</a>)</li>
</ul>
<p>Getting these set up ahead of time means session time goes to the workflow itself rather than to installation troubleshooting.</p>
</section>
<section id="when-and-where" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="when-and-where"><span class="header-section-number">6</span> When and where</h2>
<table class="caption-top table">
<colgroup>
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
</colgroup>
<thead>
<tr class="header">
<th>Session</th>
<th>Topic</th>
<th>Date</th>
<th>Time</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Part 1</td>
<td>Starting Clean (<code>toolero</code>)</td>
<td>Wednesday, October 7, 2026</td>
<td>2:00 - 4:00 PM</td>
<td>CS 3139</td>
</tr>
<tr class="even">
<td>Part 2</td>
<td>Portable Research (<code>containr</code>)</td>
<td>Wednesday, October 14, 2026</td>
<td>2:00 - 4:00 PM</td>
<td>CS 3139</td>
</tr>
<tr class="odd">
<td>Part 3</td>
<td>Scaling Out (<code>submitr</code>)</td>
<td>Thursday, October 22, 2026</td>
<td>2:00 - 4:00 PM</td>
<td>CS 3139</td>
</tr>
</tbody>
</table>
</section>
<section id="questions" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="questions"><span class="header-section-number">7</span> Questions</h2>
<p>Registration details are still being finalized. In the meantime, if you have questions or want to be notified when sign-up opens, reach out to me at <a href="mailto:erwinlares@wisc.edu">erwin.lares@wisc.edu</a></p>


</section>

 ]]></description>
  <category>workshop</category>
  <category>reproducibility</category>
  <guid>https://erwinlares.com/posts/2026-10-07-from-the-notebook-to-the-cluster-workshop-series/</guid>
  <pubDate>Wed, 07 Oct 2026 00:00:00 GMT</pubDate>
  <media:content url="https://erwinlares.com/posts/2026-10-07-from-the-notebook-to-the-cluster-workshop-series/n2c-workshop-logo-thumb.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>A Clipboard Helper</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-10-01-a-clipboard-helper/</link>
  <description><![CDATA[ 




<section id="the-problem" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="the-problem"><span class="header-section-number">1</span> The problem</h2>
<p>Here is a small ritual I perform more often than I would like to admit. I run something in the console, say a model summary, and the output looks right. Then I want it somewhere else: in an email to a collaborator, in a GitHub issue, in a message asking a colleague why a coefficient looks odd. So I reach for the mouse, drag across the output, miss the first line, drag again, and discover that the last few lines have scrolled out of view.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(mpg <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> wt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> mtcars))</span></code></pre></div></div>
<p>None of this is difficult, but it is tedious, and tedium is exactly the kind of thing a computer should absorb on my behalf. In other words, what I wanted was for R to hand me its own output, ready to paste.</p>
</section>
<section id="what-to_cb-does" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="what-to_cb-does"><span class="header-section-number">2</span> What <code>to_cb()</code> does</h2>
<p><code>to_cb()</code> (read it as “to clipboard”) takes an expression, runs it, shows you the output exactly as R would have, and copies that same text to the clipboard. Wrapping the example above is all it takes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">to_cb</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(mpg <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> wt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> mtcars)))</span></code></pre></div></div>
<p>The native pipe works too, which is how I tend to use it in practice:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">mtcars <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">to_cb</span>()</span></code></pre></div></div>
<p>Two small design decisions are worth knowing about. First, <code>to_cb()</code> returns the value of your expression invisibly, so you can drop it into the middle of a pipeline without changing what the pipeline does. Second, it copies only what R would have printed. An assignment such as <code>to_cb(y &lt;- 5)</code> prints nothing at the console, so it copies nothing.</p>
</section>
<section id="what-you-need" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="what-you-need"><span class="header-section-number">3</span> What you need</h2>
<p>Two pieces make this available in every R session, and it is worth asking why there are two. Recall that R reads a startup file, <code>~/.Rprofile</code>, once, when a session begins. I could have pasted the whole helper into that file, but I would rather keep the machinery that loads helpers separate from the helpers themselves. That way, adding a second helper later means dropping one more file into a folder, with no edits to <code>.Rprofile</code>.</p>
<p>The first piece is a short loader in <code>~/.Rprofile</code> (you can open it with <code>usethis::edit_r_profile()</code>). It sources every <code>.R</code> file it finds in <code>~/.config/R/profile.d/</code>, in name order:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">############################</span></span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># personal profile.d loader</span></span>
<span id="cb4-3"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">############################</span></span>
<span id="cb4-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sources every .R file in ~/.config/R/profile.d/, in name order, once per</span></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># session. A file that fails produces a warning instead of stopping startup.</span></span>
<span id="cb4-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">local</span>({</span>
<span id="cb4-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isTRUE</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getOption</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"personal.profile.loaded"</span>))) {</span>
<span id="cb4-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">personal.profile.loaded =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb4-9"></span>
<span id="cb4-10">        profile_dir <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path.expand</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/.config/R/profile.d"</span>)</span>
<span id="cb4-11"></span>
<span id="cb4-12">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.exists</span>(profile_dir)) {</span>
<span id="cb4-13">            profile_files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>(</span>
<span id="cb4-14">                profile_dir,</span>
<span id="cb4-15">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.[Rr]$"</span>,</span>
<span id="cb4-16">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb4-17">            )</span>
<span id="cb4-18"></span>
<span id="cb4-19">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (profile_file <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(profile_files, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"radix"</span>)) {</span>
<span id="cb4-20">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>(</span>
<span id="cb4-21">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sys.source</span>(profile_file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">envir =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">globalenv</span>()),</span>
<span id="cb4-22">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) {</span>
<span id="cb4-23">                        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">warning</span>(</span>
<span id="cb4-24">                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Skipped "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">basename</span>(profile_file), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">": "</span>,</span>
<span id="cb4-25">                            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conditionMessage</span>(e),</span>
<span id="cb4-26">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">call. =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb4-27">                        )</span>
<span id="cb4-28">                    }</span>
<span id="cb4-29">                )</span>
<span id="cb4-30">            }</span>
<span id="cb4-31">        }</span>
<span id="cb4-32">    }</span>
<span id="cb4-33">})</span></code></pre></div></div>
<p>(The <code>.d</code> in <code>profile.d</code> is not a file extension. It is an old Unix convention for a “drop-in” directory whose files are all read in order, and R attaches no special meaning to it. The folder works only because the loader above looks for it.)</p>
<p>The second piece is the helper itself, saved as <code>~/.config/R/profile.d/10-clipboard.R</code>. You can create the folder and open the file from R:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/.config/R/profile.d"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.edit</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/.config/R/profile.d/10-clipboard.R"</span>)</span></code></pre></div></div>
<p>The numeric prefix is only there to control load order if you add more files later. The full helper follows, with comments aimed at readers who have not met <code>substitute()</code> or <code>withVisible()</code> before.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The full helper, <code>10-clipboard.R</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ~/.config/R/profile.d/10-clipboard.R</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to_cb(): evaluate an expression, print its output as usual, and copy that</span></span>
<span id="cb6-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># output to the system clipboard. The expression's value is returned</span></span>
<span id="cb6-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># invisibly, so to_cb() can be dropped into a pipeline without changing it.</span></span>
<span id="cb6-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb6-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   to_cb(summary(lm(mpg ~ wt, data = mtcars)))</span></span>
<span id="cb6-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   mtcars |&gt; head() |&gt; to_cb()</span></span>
<span id="cb6-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb6-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Backends, tried in order:</span></span>
<span id="cb6-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   1. clipr, if it is installed and able to write</span></span>
<span id="cb6-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   2. native fallbacks, which need no R package:</span></span>
<span id="cb6-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#        Windows : utils::writeClipboard()</span></span>
<span id="cb6-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#        macOS   : pbcopy</span></span>
<span id="cb6-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#        Linux   : wl-copy (Wayland), then xclip, then xsel (X11)</span></span>
<span id="cb6-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb6-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If no backend works (for example over SSH, or on a CHTC node), a warning</span></span>
<span id="cb6-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># is issued and the result is still returned, so a failed copy never stops</span></span>
<span id="cb6-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a script.</span></span>
<span id="cb6-20"></span>
<span id="cb6-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># local() runs the block below in its own private environment. The two</span></span>
<span id="cb6-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># helper functions defined inside it are visible to to_cb(), but they do not</span></span>
<span id="cb6-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clutter your global environment (ls() will show only to_cb).</span></span>
<span id="cb6-24">to_cb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">local</span>({</span>
<span id="cb6-25"></span>
<span id="cb6-26">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Backend 1: the clipr package.</span></span>
<span id="cb6-27">    write_clipr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(text) {</span>
<span id="cb6-28">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># requireNamespace() checks that a package is installed without</span></span>
<span id="cb6-29">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># attaching it (no library() call). quietly = TRUE suppresses the</span></span>
<span id="cb6-30">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># loading message. It returns TRUE or FALSE.</span></span>
<span id="cb6-31">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">requireNamespace</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"clipr"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quietly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)) {</span>
<span id="cb6-32">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-33">        }</span>
<span id="cb6-34"></span>
<span id="cb6-35">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># tryCatch() runs the code and, if it throws an error, runs the</span></span>
<span id="cb6-36">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># error = function(e) handler instead of stopping. Here that turns</span></span>
<span id="cb6-37">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "clipr failed" into FALSE so we can fall back to a native tool.</span></span>
<span id="cb6-38">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># allow_non_interactive = TRUE lets clipr write under Rscript and</span></span>
<span id="cb6-39">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># quarto render, where it would otherwise refuse.</span></span>
<span id="cb6-40">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>({</span>
<span id="cb6-41">            clipr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_clip</span>(text, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow_non_interactive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-42">            <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb6-43">        }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-44">    }</span>
<span id="cb6-45"></span>
<span id="cb6-46">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Backend 2: tools that ship with the operating system.</span></span>
<span id="cb6-47">    write_native <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(text) {</span>
<span id="cb6-48">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sys.info() returns a named character vector. [[ ]] pulls out one</span></span>
<span id="cb6-49">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># element by name as a plain string: "Windows", "Darwin" (macOS),</span></span>
<span id="cb6-50">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># or "Linux".</span></span>
<span id="cb6-51">        sysname <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.info</span>()[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sysname"</span>]]</span>
<span id="cb6-52"></span>
<span id="cb6-53">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">identical</span>(sysname, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Windows"</span>)) {</span>
<span id="cb6-54">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>({</span>
<span id="cb6-55">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Windows wants lines separated by "\r\n", so we paste the</span></span>
<span id="cb6-56">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># lines together ourselves. Format 13 is CF_UNICODETEXT,</span></span>
<span id="cb6-57">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># which keeps accented characters intact. The utils::</span></span>
<span id="cb6-58">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prefix means "the function from the utils package".</span></span>
<span id="cb6-59">                utils<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">writeClipboard</span>(</span>
<span id="cb6-60">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(text, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>),</span>
<span id="cb6-61">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>L</span>
<span id="cb6-62">                )</span>
<span id="cb6-63">                <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb6-64">            }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))</span>
<span id="cb6-65">        }</span>
<span id="cb6-66"></span>
<span id="cb6-67">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># macOS has one tool. On Linux we build a list of candidates and</span></span>
<span id="cb6-68">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># try them in order. c() drops NULL, so wl-copy is only in the</span></span>
<span id="cb6-69">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># list when WAYLAND_DISPLAY is set (nzchar() is TRUE for a</span></span>
<span id="cb6-70">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># non-empty string).</span></span>
<span id="cb6-71">        commands <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">identical</span>(sysname, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Darwin"</span>)) {</span>
<span id="cb6-72">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pbcopy"</span></span>
<span id="cb6-73">        } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb6-74">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb6-75">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nzchar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.getenv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WAYLAND_DISPLAY"</span>))) <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wl-copy"</span>,</span>
<span id="cb6-76">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xclip -selection clipboard"</span>,</span>
<span id="cb6-77">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xsel --clipboard --input"</span></span>
<span id="cb6-78">            )</span>
<span id="cb6-79">        }</span>
<span id="cb6-80"></span>
<span id="cb6-81">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (command <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> commands) {</span>
<span id="cb6-82">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># strsplit() cuts the command on spaces, and [[1]][1] takes the</span></span>
<span id="cb6-83">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># first word, which is the program name ("xclip", "xsel", ...).</span></span>
<span id="cb6-84">            binary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(command, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fixed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb6-85"></span>
<span id="cb6-86">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sys.which() returns the program's full path, or "" if the</span></span>
<span id="cb6-87">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># program is not installed. If it is missing, skip to the next</span></span>
<span id="cb6-88">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># candidate.</span></span>
<span id="cb6-89">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nzchar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.which</span>(binary))) {</span>
<span id="cb6-90">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">next</span></span>
<span id="cb6-91">            }</span>
<span id="cb6-92"></span>
<span id="cb6-93">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pipe() starts the program and gives us a connection we can</span></span>
<span id="cb6-94">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># write text into, as if we were typing it on the command</span></span>
<span id="cb6-95">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># line. "w" means write mode.</span></span>
<span id="cb6-96">            connection <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pipe</span>(command, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">open =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"w"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">encoding =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UTF-8"</span>)</span>
<span id="cb6-97">            wrote <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>({</span>
<span id="cb6-98">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">writeLines</span>(text, connection)</span>
<span id="cb6-99">                <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb6-100">            }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-101"></span>
<span id="cb6-102">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># close() ends the connection. For a pipe it returns the</span></span>
<span id="cb6-103">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># program's exit status: 0 (or NULL) means success.</span></span>
<span id="cb6-104">            status <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">close</span>(connection), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L)</span>
<span id="cb6-105"></span>
<span id="cb6-106">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (wrote <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(status) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">identical</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(status), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>L))) {</span>
<span id="cb6-107">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-108">            }</span>
<span id="cb6-109">        }</span>
<span id="cb6-110"></span>
<span id="cb6-111">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb6-112">    }</span>
<span id="cb6-113"></span>
<span id="cb6-114">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This is the function that to_cb actually becomes.</span></span>
<span id="cb6-115">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(expr) {</span>
<span id="cb6-116">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># R normally evaluates an argument and hands the function its</span></span>
<span id="cb6-117">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># result. substitute() instead captures the code you typed, before</span></span>
<span id="cb6-118">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># it runs. For to_cb(summary(x)), expr now holds the call</span></span>
<span id="cb6-119">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># summary(x), not the summary itself. That lets us run it</span></span>
<span id="cb6-120">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ourselves below, inside capture.output(), and check whether R</span></span>
<span id="cb6-121">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># would have printed the result.</span></span>
<span id="cb6-122">        expr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substitute</span>(expr)</span>
<span id="cb6-123"></span>
<span id="cb6-124">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># parent.frame() is the environment that called to_cb(), such as</span></span>
<span id="cb6-125">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># your console. We evaluate the code there so it can see your</span></span>
<span id="cb6-126">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># variables (x, mtcars, and so on).</span></span>
<span id="cb6-127">        env <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parent.frame</span>()</span>
<span id="cb6-128"></span>
<span id="cb6-129">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># capture.output() runs the code inside the braces, but instead of</span></span>
<span id="cb6-130">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># showing printed text on screen, it returns that text as a</span></span>
<span id="cb6-131">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># character vector, one element per line.</span></span>
<span id="cb6-132">        output <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">capture.output</span>({</span>
<span id="cb6-133">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># eval() runs the captured code in env. withVisible() records</span></span>
<span id="cb6-134">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># whether R would normally print the result: visible is TRUE</span></span>
<span id="cb6-135">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for summary(x) and FALSE for an assignment like y &lt;- 5, so</span></span>
<span id="cb6-136">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># that to_cb(y &lt;- 5) copies nothing, as the console would show</span></span>
<span id="cb6-137">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># nothing.</span></span>
<span id="cb6-138">            result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">withVisible</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(expr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">envir =</span> env))</span>
<span id="cb6-139"></span>
<span id="cb6-140">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>visible) {</span>
<span id="cb6-141">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value)</span>
<span id="cb6-142">            }</span>
<span id="cb6-143">        })</span>
<span id="cb6-144"></span>
<span id="cb6-145">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(output)) {</span>
<span id="cb6-146">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Show the captured text on screen, since capture.output()</span></span>
<span id="cb6-147">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># swallowed it, plus a trailing blank line.</span></span>
<span id="cb6-148">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(output, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb6-149">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb6-150">        } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb6-151">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">message</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nothing to copy."</span>)</span>
<span id="cb6-152">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value))</span>
<span id="cb6-153">        }</span>
<span id="cb6-154"></span>
<span id="cb6-155">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># || stops at the first TRUE. So the native tools are tried only if</span></span>
<span id="cb6-156">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clipr is missing or failed. If both fail, warn but carry on.</span></span>
<span id="cb6-157">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_clipr</span>(output) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_native</span>(output))) {</span>
<span id="cb6-158">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">warning</span>(</span>
<span id="cb6-159">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Could not reach a system clipboard (clipr and native tools "</span>,</span>
<span id="cb6-160">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both failed). Output was not copied."</span>,</span>
<span id="cb6-161">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">call. =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb6-162">            )</span>
<span id="cb6-163">        }</span>
<span id="cb6-164"></span>
<span id="cb6-165">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># invisible() returns the value without printing it, so</span></span>
<span id="cb6-166">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to_cb(x) does not print x a second time.</span></span>
<span id="cb6-167">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value)</span>
<span id="cb6-168">    }</span>
<span id="cb6-169">})</span></code></pre></div></div>
</div>
</div>
</div>
<p>A few practical notes. The helper uses the <code>clipr</code> package when it is installed and falls back to tools the operating system already provides, so <code>clipr</code> is optional. On macOS and Windows there is nothing else to install. On Linux you need one of <code>xclip</code>, <code>xsel</code>, or <code>wl-clipboard</code> (the last for Wayland). On Windows, <code>~</code> usually points at your Documents folder, so both <code>~/.Rprofile</code> and <code>~/.config/R/profile.d/</code> live there.</p>
</section>
<section id="existing-project-or-new-project" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="existing-project-or-new-project"><span class="header-section-number">4</span> Existing project or new project?</h2>
<p>Everything so far assumes you start R in a folder that has no <code>.Rprofile</code> of its own. Projects change that, and this is where it pays to slow down. R reads exactly one <code>.Rprofile</code>: the project’s, if the working directory has one, and the one in your home directory otherwise. It follows that the moment a project has its own profile, your personal one stops loading, and <code>to_cb()</code> goes with it. Any project that uses renv has such a file, since renv writes one containing <code>source("renv/activate.R")</code>. Nothing warns you. The helper is simply not there.</p>
<p><strong>Adding it to an existing project.</strong> The remedy is to have the project’s profile load yours. Open the project’s <code>.Rprofile</code> and add a guarded <code>source()</code> call at the end, after renv’s activation line:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/.Rprofile"</span>)) {</span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/.Rprofile"</span>)</span>
<span id="cb7-3">}</span></code></pre></div></div>
<p>The <code>file.exists()</code> guard matters if the project is shared. A collaborator who lacks a personal profile gets no error, just no helper. The cost of this route is that it is manual and per project: you have to remember to do it each time, and the way you find out you forgot is a “could not find function” error at an inconvenient moment.</p>
<p><strong>Starting a new project with toolero.</strong> <code>toolero::init_project()</code> can write that block for you through its <code>use_rprofile</code> argument:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">toolero<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb8-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/Documents/my-project"</span>,</span>
<span id="cb8-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_rprofile =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb8-4">)</span></code></pre></div></div>
<p>Here <code>TRUE</code> appends the guarded block above to the new project’s <code>.Rprofile</code>, after renv’s activation line. A character string sources a different file instead, which is handy if your profile lives in a dotfiles repository (<code>use_rprofile = "~/dotfiles/rprofile"</code>). The existence check is written into the block itself, so it runs at every session start, and a profile you create or edit after the project exists is still picked up. (If <code>use_rprofile</code> is missing from the version of toolero you have installed, the development version on GitHub, available through <code>pak::pak("erwinlares/toolero")</code>, is the one to try.)</p>
<p>Comparing the two, the block of code is the same, so the difference lies in who writes it and when you decide. With <code>init_project()</code> the decision is a single argument at creation time. With an existing project it is a manual edit that is easy to forget.</p>
<p>Does sourcing a personal profile into a project cost anything? In this case, I do not think it does. What the profile carries here is a default author for new packages, a preferred package repository, and a clipboard helper meant for the console. None of these is a dependency of the project’s code, and renv still governs the dependencies that matter. If a preferred repository cannot supply a package the lockfile asks for, the restore fails loudly instead of quietly installing something else. And because <code>to_cb()</code> exists to be used interactively, nothing running on a server or a cluster node has any reason to call it.</p>
<p>Two mechanical facts are worth knowing all the same. First, if the same option is set in both files, the later line wins, and because the block is appended last, your personal value overrides the project’s. Second, renv restricts R to the project’s own library, so a package you installed globally may not be visible inside the project. That is the reason <code>to_cb()</code> does not depend on <code>clipr</code>: if <code>clipr</code> is absent from the project library, the helper falls back to the operating system’s own tools and carries on.</p>
</section>
<section id="caveats" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="caveats"><span class="header-section-number">5</span> Caveats</h2>
<p>A few honest limits. <code>to_cb()</code> copies only what R prints to standard output, so messages and warnings from your code still appear at the console but are not copied. A remote session (SSH, a Posit Connect server, a cluster node) has no access to the clipboard on your own machine, so there you will see a warning that nothing was copied, and your code will still run to completion. Finally, the Windows branch is the least exercised of the three, so I would treat it with some suspicion until it has seen real use.</p>
</section>
<section id="where-this-leaves-us" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="where-this-leaves-us"><span class="header-section-number">6</span> Where this leaves us</h2>
<p>I wanted R to hand me its own output, ready to paste. A short loader in <code>~/.Rprofile</code>, a single helper file in <code>~/.config/R/profile.d/</code>, and one extra line in any project that has a profile of its own are enough to get there. And once a folder of drop-in helpers exists, the next small annoyance is one file away from being solved.</p>


</section>

 ]]></description>
  <category>r</category>
  <category>data-science</category>
  <category>productivity</category>
  <category>coding</category>
  <category>toolero</category>
  <guid>https://erwinlares.com/posts/2026-10-01-a-clipboard-helper/</guid>
  <pubDate>Thu, 01 Oct 2026 00:00:00 GMT</pubDate>
  <media:content url="https://erwinlares.com/posts/2026-10-01-a-clipboard-helper/to_cb-thumb.png" medium="image" type="image/png" height="108" width="144"/>
</item>
<item>
  <title>A small package for a small habit: cronR</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-08-21-schedule-your-job-with-the-cronr-package/</link>
  <description><![CDATA[ 




<p>I found something small and useful this week, and I wanted to pass it along before I forget: <a href="https://github.com/bnosac/cronR"><code>cronR</code></a>, an R package by BNOSAC for managing cron jobs from inside R itself.</p>
<p>Before I get to the package, a quick word on cron jobs for anyone who hasn’t met one. A cron job is just a scheduled task — a command that runs automatically at a time you specify, without you having to be there to type it in. The name comes from the Greek <em>chronos</em>, time, which feels appropriate. On Unix-like systems (which is to say, most servers, and your Mac or Linux box too), a background program called the cron daemon quietly checks a list of these scheduled tasks — the crontab — once a minute, and runs whatever is due. Set it once, and it runs on your behalf, whether or not you’re at your desk.</p>
<p>That last part is where this becomes relevant to a researcher’s actual day. Picture the scene: you have a script that pulls fresh data, refits a model, and knits a short report. Running it by hand means remembering to run it, then waiting around for it to finish. Instead, you could schedule it for 7:45 AM, right before your commute wraps up, so that by the time you sit down with your coffee, the report is already sitting in your inbox or your project folder. Or set it to run at noon, just as you’re heading out to lunch, so the afternoon starts with results instead of a spinner. The job runs whether you’re watching or not — which is, after all, the entire point.</p>
<p><code>cronR</code> makes this approachable from R, without requiring you to hand-edit a crontab file (a task with its own particular syntax and its own particular ways of going wrong). A minimal example:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cronR)</span>
<span id="cb1-2"></span>
<span id="cb1-3">f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path/to/my_script.R"</span></span>
<span id="cb1-4">cmd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cron_rscript</span>(f)</span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cron_add</span>(cmd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frequency =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"daily"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">at =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"07:45"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"morning_report"</span>)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cron_ls</span>()</span></code></pre></div></div>
<p><code>cron_add()</code> schedules the job, <code>cron_ls()</code> lists what’s currently scheduled, and <code>cron_rm()</code> or <code>cron_clear()</code> remove jobs when you no longer need them. The package also ships an RStudio add-in (Addins &gt; Schedule R scripts on Linux/Unix), which gives you a small form-based interface if you’d rather not remember the function arguments at all.</p>
<section id="if-even-thats-too-much-fuss" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="if-even-thats-too-much-fuss"><span class="header-section-number">1</span> If even that’s too much fuss</h2>
<p>If setting up <code>cronR</code> still feels like more infrastructure than the moment calls for, RStudio’s built-in <strong>Background Jobs</strong> panel is worth knowing about. It lets you launch an R script in a separate background process — right from the IDE, no cron daemon involved — and keep working in your main session while it runs. You lose the “come back tomorrow morning and it’s done” quality of a real cron job, since background jobs don’t survive you closing RStudio, but for a script that just needs to run <em>without blocking you right now</em> (a long model fit, a big data pull), it’s the lower-friction option. You’ll find it under the Jobs tab, or via <code>rstudioapi::jobRunScript()</code> if you’d rather script it.</p>
<p>Two tools, two levels of commitment: <code>cronR</code> for genuinely unattended, recurring work, and Background Jobs for the more modest ask of getting your console back while something runs.</p>


</section>

 ]]></description>
  <category>r</category>
  <category>coding</category>
  <category>productivity</category>
  <category>announcement</category>
  <guid>https://erwinlares.com/posts/2026-08-21-schedule-your-job-with-the-cronr-package/</guid>
  <pubDate>Fri, 21 Aug 2026 00:00:00 GMT</pubDate>
  <media:content url="https://erwinlares.com/posts/2026-08-21-schedule-your-job-with-the-cronr-package" medium="image"/>
</item>
<item>
  <title>Organizing a Fund Raising Seminar</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/</link>
  <description><![CDATA[ 




<section id="what-happened" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="what-happened"><span class="header-section-number">1</span> What happened</h2>
<p>On June 24, 2026, two earthquakes — both magnitude 7 or greater — struck northwestern and central Venezuela. They were large strike-slip events, and between them they have killed more than 4,400 people and injured over 16,700. Recovery is still underway as I write this, and I suspect, unfortunately, that the toll hasn’t finished climbing.</p>
<p>I heard about it the way I imagine a lot of people in this aikido community did: a message forwarded from someone with family there, then another, then the numbers themselves. There wasn’t much of a decision to make once the scale of it set in. When something happens to a place you’re from, or a place your training partners are from, you do what you can with what you have. What we had was a mat, and a network of dojos willing to open it up.</p>
</section>
<section id="what-came-together" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="what-came-together"><span class="header-section-number">2</span> What came together</h2>
<p>The idea of a fundraising seminar went out to a few dojos almost as an afterthought — less a proposal than an assumption that of course we’d do this. Florida Aikikai, Aikido Miramar, Kenosha Aikikai, and our own dojo all said yes almost as soon as it was asked. That speed wasn’t really about any one person pushing for it. The sense of duty was already there, spread across a lot of people, waiting for a reason to act on it.</p>
<p>We decided to funnel whatever we raised through <a href="https://www.globalempowermentmission.org/">Global Empowerment Mission (GEM)</a>, an organization with a track record of getting aid to disaster zones quickly. Florida Aikikai offered their space and handled most of the on-the-ground logistics, and Peter and Penny Bernath made sure instructors and students arriving from out of town had what they needed. That kind of generosity — opening a space, sorting out the details — doesn’t always get mentioned, but it’s usually what makes an effort like this possible in the first place.</p>
</section>
<section id="what-the-mat-looked-like-that-saturday" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="what-the-mat-looked-like-that-saturday"><span class="header-section-number">3</span> What the mat looked like that Saturday</h2>
<p>The mat was full. People trained, and in training, gave their time toward something larger than the technique itself. I taught two techniques that day, uchi kaitennage and nikkyo, chosen less for the techniques themselves than for what they let me say about connection — something I’ve been trying to get across to my own students for a while now. The framework came from Terry Leonard sensei, and it’s a little counterintuitive the first time you hear it: nage holds the knife, and holds it assertively. That sounds backward — isn’t the knife supposed to be the threat? — but the logic is that its presence is exactly what keeps nage honest. Let go of the connection, and the knife doesn’t go away; it ends up pointing back at you.</p>
<p>From there, everything followed the Capital Aikikai Federation’s usual approach: connect to uke at the edge of your own space, settle into that connection before doing anything else, keep two lines, move linearly, keep uke in your center. What decided the outcome was one detail — how the knife got taken. Grab it from the top and the motion wants to slash, which is where uchi kaitennage comes from. Grab it from the bottom and it wants to stab instead, and that’s nikkyo. A small mechanical choice, a different technique entirely — which is probably why I still remember demoing it more clearly than I remember most of what came after.</p>
<p>Not everyone could be on the mat, though. Some gave online instead, in the days around the event. Between the two, the community raised close to $10,000 most of it, as it happens, in the final few days, once word reached more people. Seventy-two separate donations went into that total, most of them modest, somewhere between $100 and $150. That’s worth noting on its own: this wasn’t one or two large gifts carrying the total, but a lot of people independently deciding it was worth doing something.</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/index_files/figure-html/unnamed-chunk-1-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>I’m grateful to everyone who trained, gave, or helped in some smaller way I may not even know about. I’d also like to thank our photographer, <span class="citation" data-cites="wmeleanfoto">@wmeleanfoto</span> on Instagram, for documenting the day.</p>
</section>
<section id="what-i-keep-thinking-about" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="what-i-keep-thinking-about"><span class="header-section-number">4</span> What I keep thinking about</h2>
<p>Recovery in Venezuela is still going, and it’ll keep going long after this post is off the front page. What we did was small next to that — one Saturday, a small group of people, some money moved through an organization that knows how to get it where it needs to go. It’s not going to rebuild anything o n its own. But it wasn’t nothing either, and I’m glad I got to be part of it.</p>
<p><em>#Venezuela #Aikido #FloridaAikikai #CapitalAikikaiofWisconsin #AikidoMiramar #KenoshaAikikai</em></p>
<div class="photo-grid">
<p><a href="Solidarity-093.jpg" class="lightbox" data-gallery="post-slug" title="Carlos Frick demoing kokyunage"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-093.jpg" class="img-fluid" alt="Carlos Frick demoing kokyunage"></a> <a href="Solidarity-123.jpg" class="lightbox" data-gallery="post-slug" title="Ricardo Manzo demoing yonkyo"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-123.jpg" class="img-fluid" alt="Ricardo Manzo demoing yonkyo"></a> <a href="Solidarity-222.jpg" class="lightbox" data-gallery="post-slug" title="Omar Morales demoing shihonage"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-222.jpg" class="img-fluid" alt="Omar Morales demoing shihonage"></a> <a href="Solidarity-252.jpg" class="lightbox" data-gallery="post-slug" title="Isabel de la Vega demoing kokyunage"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-252.jpg" class="img-fluid" alt="Isabel de la Vega demoing kokyunage"></a> <a href="Solidarity-174.jpg" class="lightbox" data-gallery="post-slug" title="Emmanuel Herzog demoing ikkyo"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-174.jpg" class="img-fluid" alt="Emmanuel Herzog demoing ikkyo"></a> <a href="Solidarity-040.jpg" class="lightbox" data-gallery="post-slug" title="Erwin Lares demoing nikkyo"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-040.jpg" class="img-fluid" alt="Erwin Lares demoing nikkyo"></a> <a href="Solidarity-342.jpg" class="lightbox" data-gallery="post-slug" title="Bowing in gratitude"><img src="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-342.jpg" class="img-fluid" alt="Bowing in gratitude"></a></p>
</div>


</section>

 ]]></description>
  <category>aikido</category>
  <category>journal</category>
  <category>personal</category>
  <guid>https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/</guid>
  <pubDate>Thu, 16 Jul 2026 00:00:00 GMT</pubDate>
  <media:content url="https://erwinlares.com/posts/2026-07-16-organizing-a-fund-raising-seminar/Solidarity-001-thumb.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Cloning a GitLab Repository into your BadgerCompute RStudio Session</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-07-02-clone-your-gitlab-repo-into-badger-computer/</link>
  <description><![CDATA[ 
<div class="rci-header">
  <img src="https://erwinlares.com/posts/rci-banner.png" alt="Research Cyberinfrastructure at UW-Madison">
  <div class="rci-header-text">
    <span class="rci-title">Research Cyberinfrastructure</span>
    <span class="rci-subtitle">Division of Information Technology &nbsp;·&nbsp; UW–Madison</span>
  </div>
</div>




<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Prerequisites
</div>
</div>
<div class="callout-body-container callout-body">
<ul>
<li>An active BadgerCompute session at <code>launch.badgercompute.wisc.edu</code></li>
<li>A UW NetID with <strong>Reporter-level access or higher</strong> on the target GitLab project</li>
<li>A Personal Access Token generated from your user profile at<br>
<code>https://git.doit.wisc.edu/-/user_settings/personal_access_tokens</code>
<ul>
<li><code>read_repository</code> scope — required for cloning</li>
<li><code>write_repository</code> scope — required if you intend to push changes</li>
</ul></li>
<li>A Terminal open in RStudio Server: <strong>Tools → Terminal → New Terminal</strong></li>
</ul>
</div>
</div>
<hr>
<section id="step-1-navigate-to-persistent-storage" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="step-1-navigate-to-persistent-storage"><span class="header-section-number">1</span> Step 1: Navigate to Persistent Storage</h2>
<p>All work must be kept inside <code>~/work</code> — it is the only directory that persists across BadgerCompute session resets.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> ~/work</span></code></pre></div></div>
<p>Your prompt should now show <code>~/work</code> as the current directory.</p>
<hr>
</section>
<section id="step-2-verify-git-is-available" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="step-2-verify-git-is-available"><span class="header-section-number">2</span> Step 2: Verify git is Available</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span> git</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--version</span></span></code></pre></div></div>
<p>You should see a path like <code>/usr/bin/git</code> and a version string such as <code>git version 2.x.x</code>. Git is pre-installed in the BadgerCompute environment.</p>
<hr>
</section>
<section id="step-3-configure-git-identity" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="step-3-configure-git-identity"><span class="header-section-number">3</span> Step 3: Configure git Identity</h2>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Warning</span>This setting does not persist across sessions
</div>
</div>
<div class="callout-body-container callout-body">
<p><code>~/.gitconfig</code> lives outside <code>~/work</code> and is deleted on session reset. You will need to re-run these lines at the start of each new BadgerCompute session. See the Session Reset section for a setup script that automates this.</p>
</div>
</div>
<p>Set the name and email that will be attached to your commits:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> user.name <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Your Name"</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> user.email <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"netid@wisc.edu"</span></span></code></pre></div></div>
<hr>
</section>
<section id="step-4-set-up-persistent-credential-storage" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="step-4-set-up-persistent-credential-storage"><span class="header-section-number">4</span> Step 4: Set Up Persistent Credential Storage</h2>
<p>By default, git stores credentials in <code>~/.git-credentials</code>, which is outside <code>~/work</code> and wiped on reset. Anchor it to <code>~/work</code> with a symlink so your token survives session resets:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">touch</span> ~/work/.git-credentials</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-s</span> ~/work/.git-credentials ~/.git-credentials</span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> credential.helper store</span></code></pre></div></div>
<p>Verify the symlink is in place:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ls</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-la</span> ~/.git-credentials</span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Expected output:</span></span>
<span id="cb5-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># lrwxrwxrwx ... /home/jovyan/.git-credentials -&gt; work/.git-credentials</span></span></code></pre></div></div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>If you have run this before, <code>ln</code> will report that the symlink already exists — that is expected and means your credentials are already persisted. No action needed.</p>
</div>
</div>
<hr>
</section>
<section id="step-5-clone-the-repository" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="step-5-clone-the-repository"><span class="header-section-number">5</span> Step 5: Clone the Repository</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> clone https://git.doit.wisc.edu/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>group<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>project<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>.git</span></code></pre></div></div>
<p>When prompted:</p>
<ul>
<li><strong>Username:</strong> your NetID (e.g.&nbsp;<code>lares</code>)</li>
<li><strong>Password:</strong> your Personal Access Token</li>
</ul>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Warning</span>Treat your PAT like a password
</div>
</div>
<div class="callout-body-container callout-body">
<p>Never paste your Personal Access Token into a shared script or commit it to a repository. It grants access to your GitLab account and should be kept private.</p>
</div>
</div>
<p>After a successful clone, credentials are written to <code>~/work/.git-credentials</code> automatically. Subsequent <code>git pull</code> and <code>git push</code> commands will not prompt again.</p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Important</span>Getting a 403 error?
</div>
</div>
<div class="callout-body-container callout-body">
<p>A 403 “not allowed to download code” error means one of:</p>
<ol type="1">
<li><p><strong>Wrong token type</strong> — you may have generated a Project Access Token (a bot account) instead of a Personal Access Token. Verify by running:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-H</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PRIVATE-TOKEN: &lt;your-token&gt;"</span> https://git.doit.wisc.edu/api/v4/user</span></code></pre></div></div>
<p>The response should show your own NetID and <code>"bot": false</code>. If you see <code>"bot": true</code>, generate a new token from your user profile instead of the project settings.</p></li>
<li><p><strong>Insufficient access level</strong> — Guest access (level 10) cannot clone. You need Reporter (level 20) or higher. Ask the project owner to update your role at:<br>
<code>https://git.doit.wisc.edu/&lt;group&gt;/&lt;project&gt;/-/project_members</code></p></li>
</ol>
</div>
</div>
<hr>
</section>
<section id="step-6-verify-the-clone-and-remote" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="step-6-verify-the-clone-and-remote"><span class="header-section-number">6</span> Step 6: Verify the Clone and Remote</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>project-name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> remote <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-v</span></span></code></pre></div></div>
<p>Expected output:</p>
<pre><code>origin  https://git.doit.wisc.edu/&lt;group&gt;/&lt;project&gt;.git (fetch)
origin  https://git.doit.wisc.edu/&lt;group&gt;/&lt;project&gt;.git (push)</code></pre>
<hr>
</section>
<section id="step-7-open-the-project-in-rstudio" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="step-7-open-the-project-in-rstudio"><span class="header-section-number">7</span> Step 7: Open the Project in RStudio</h2>
<p>With the repository cloned, open it as an RStudio Project:</p>
<p><strong>File → Open Project → navigate to <code>~/work/&lt;project-name&gt;</code></strong></p>
<p>If the repo contains an <code>.Rproj</code> file, open that directly. Otherwise create a new project in the cloned directory:</p>
<p><strong>File → New Project → Existing Directory → select <code>~/work/&lt;project-name&gt;</code></strong></p>
<p>The <strong>Git pane</strong> will appear in the upper-right panel (alongside Environment and History), giving you point-and-click access to pull, commit, push, and diff without leaving RStudio.</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Tip
</div>
</div>
<div class="callout-body-container callout-body">
<p>If the Git pane does not appear after opening the project, try restarting RStudio within the session: <strong>Session → Restart R</strong>.</p>
</div>
</div>
<hr>
</section>
<section id="handling-session-resets" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="handling-session-resets"><span class="header-section-number">8</span> Handling Session Resets</h2>
<p>BadgerCompute sessions shut down after <strong>4 hours</strong> or <strong>10 minutes of inactivity</strong>. On reset, <code>~/.gitconfig</code> is deleted but <code>~/work/.git-credentials</code> survives.</p>
<p>Save the following script <strong>once</strong> to <code>~/work/setup-git.sh</code> to restore your config quickly at the start of each session:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#!/bin/bash</span></span>
<span id="cb10-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ~/work/setup-git.sh</span></span>
<span id="cb10-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run at the start of each BadgerCompute session.</span></span>
<span id="cb10-4"></span>
<span id="cb10-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> user.name <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Your Name"</span></span>
<span id="cb10-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> user.email <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"netid@wisc.edu"</span></span>
<span id="cb10-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">git</span> config <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--global</span> credential.helper store</span>
<span id="cb10-8"></span>
<span id="cb10-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Restore symlink if missing</span></span>
<span id="cb10-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">[</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">!</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-L</span> ~/.git-credentials <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">]</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">then</span></span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">touch</span> ~/work/.git-credentials</span>
<span id="cb10-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-s</span> ~/work/.git-credentials ~/.git-credentials</span>
<span id="cb10-13">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Credentials symlink restored."</span></span>
<span id="cb10-14"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span></span>
<span id="cb10-15">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Credentials symlink already in place."</span></span>
<span id="cb10-16"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fi</span></span>
<span id="cb10-17"></span>
<span id="cb10-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"git config restored."</span></span></code></pre></div></div>
<p>Make it executable once:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chmod</span> +x ~/work/setup-git.sh</span></code></pre></div></div>
<p>Run it at the start of each new session:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bash</span> ~/work/setup-git.sh</span></code></pre></div></div>
<p>Or from the RStudio R console:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bash ~/work/setup-git.sh"</span>)</span></code></pre></div></div>
<hr>
</section>
<section id="quick-reference" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="quick-reference"><span class="header-section-number">9</span> Quick Reference</h2>
<table class="caption-top table">
<colgroup>
<col style="width: 35%">
<col style="width: 65%">
</colgroup>
<thead>
<tr class="header">
<th>Task</th>
<th>Command</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Verify git</td>
<td><code>git --version</code></td>
</tr>
<tr class="even">
<td>Set identity</td>
<td><code>git config --global user.name "Name"</code></td>
</tr>
<tr class="odd">
<td>Set email</td>
<td><code>git config --global user.email "netid@wisc.edu"</code></td>
</tr>
<tr class="even">
<td>Enable credential store</td>
<td><code>git config --global credential.helper store</code></td>
</tr>
<tr class="odd">
<td>Check symlink</td>
<td><code>ls -la ~/.git-credentials</code></td>
</tr>
<tr class="even">
<td>Clone repo</td>
<td><code>git clone https://git.doit.wisc.edu/&lt;group&gt;/&lt;project&gt;.git</code></td>
</tr>
<tr class="odd">
<td>Verify remote</td>
<td><code>git remote -v</code></td>
</tr>
<tr class="even">
<td>Restore session config</td>
<td><code>bash ~/work/setup-git.sh</code></td>
</tr>
</tbody>
</table>
<hr>
</section>
<section id="see-also" class="level2" data-number="10">
<h2 data-number="10" class="anchored" data-anchor-id="see-also"><span class="header-section-number">10</span> See Also</h2>
<ul>
<li><a href="https://badgercompute.wisc.edu/docs/">BadgerCompute Documentation</a> — general platform documentation</li>
<li><a href="https://badgercompute.wisc.edu/policies/">BadgerCompute Policies</a> — usage policies and session limits</li>
<li><a href="https://git.doit.wisc.edu">UW-Madison GitLab</a> — <code>git.doit.wisc.edu</code> home</li>
<li><a href="https://community.badgercompute.wisc.edu">BadgerCompute Community Forum</a> — peer support and announcements</li>
</ul>


</section>

 ]]></description>
  <category>data-science</category>
  <category>r</category>
  <category>linguistics</category>
  <category>pottery</category>
  <category>aikido</category>
  <category>brug</category>
  <category>personal</category>
  <category>reproducibility</category>
  <category>productivity</category>
  <category>coding</category>
  <guid>https://erwinlares.com/posts/2026-07-02-clone-your-gitlab-repo-into-badger-computer/</guid>
  <pubDate>Thu, 02 Jul 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Notebook 2 Cluster</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-07-01-notebook-2-cluster-1-continue-with-the-document/</link>
  <description><![CDATA[ 
<div class="rci-header">
  <img src="https://erwinlares.com/posts/rci-banner.png" alt="Research Cyberinfrastructure at UW-Madison">
  <div class="rci-header-text">
    <span class="rci-title">Research Cyberinfrastructure</span>
    <span class="rci-subtitle">Division of Information Technology &nbsp;·&nbsp; UW–Madison</span>
  </div>
</div>




<section id="the-long-game" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="the-long-game"><span class="header-section-number">1</span> The long game</h2>
<p>In Part 0, we gave the project a home. We created a project structure that was not only useful for local work, but also prepared for the later steps in this series: writing a reproducible analysis document, deriving a runnable script, containerizing the software environment, and eventually submitting the work to CHTC.</p>
<p>That order matters.</p>
<p>A project that starts with a stable structure is easier to reason about. Raw data has a predictable location. Results have a predictable destination. Future job inputs have a place to go. The analysis is no longer just a script somewhere on a laptop. It belongs to a project.</p>
<p>In Part 1, we create the document that will carry the analysis.</p>
<p>The point of this post is not simply that Quarto is a good reporting tool, although it is. The larger point is that a Quarto document can become the source of truth for an analysis. Prose, code, outputs, and decisions live together. From that document, we can derive the standalone <code>.R</code> script that later stages of the workflow will need.</p>
<p>That distinction is important for the long game:</p>
<pre class="text"><code>.qmd document  -&gt; human-readable source of truth
.R script      -&gt; machine-executable derived artifact</code></pre>
<p>The <code>.qmd</code> is where we explain the analysis. The <code>.R</code> file is what we will eventually run outside the document, containerize, and hand to a scheduler.</p>
<p>If those two files are maintained separately by hand, they can drift apart. If the <code>.R</code> file is derived from the <code>.qmd</code>, the relationship is clearer: edit the document, render the document, regenerate the script.</p>
<p>That is the role of <code>toolero::create_qmd()</code> in this workflow.</p>
</section>
<section id="where-this-post-sits-in-the-sequence" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="where-this-post-sits-in-the-sequence"><span class="header-section-number">2</span> Where this post sits in the sequence</h2>
<p>This series follows a deliberate path:</p>
<pre class="text"><code>Part 0  create the project home     -&gt; toolero::init_project()
Part 1  create the document/code    -&gt; toolero::create_qmd()
Part 2  containerize the project    -&gt; containr
Part 3  submit the first job        -&gt; submitr single-job workflow
Part 4  submit many jobs            -&gt; toolero::write_by_group() + submitr</code></pre>
<p>Each step prepares for the next one.</p>
<p>In Part 0, we used <code>toolero::init_project()</code> to create a project called <code>palmer-penguins-analysis</code>. We also made one project-specific choice: because we know this analysis will eventually be split into job-sized inputs, we created <code>data/jobs/</code> from the beginning.</p>
<p>At the start of this post, assume the project has this shape:</p>
<pre class="text"><code>palmer-penguins-analysis/
├── data/
│   └── jobs/
├── data-raw/
│   └── palmer-penguins.csv
├── docs/
├── images/
├── plots/
├── R/
├── results/
└── scripts/</code></pre>
<p>The dataset lives at:</p>
<pre class="text"><code>data-raw/palmer-penguins.csv</code></pre>
<p>That path will appear throughout the post. The name is intentionally specific. A file called <code>data.csv</code> is convenient in the moment, but it becomes vague quickly. A file called <code>palmer-penguins.csv</code> tells us what the input is before we open it.</p>
</section>
<section id="why-start-with-the-document" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="why-start-with-the-document"><span class="header-section-number">3</span> Why start with the document?</h2>
<p>Most research projects start as a script. That is understandable. A script is direct. It lets you load the data, try an idea, make a plot, and keep moving.</p>
<p>The difficulty appears later.</p>
<p>A script can tell you what the code did, but it often does not tell you why the analysis was written that way. It may not record which decisions were exploratory and which became part of the final workflow. It may not explain why a particular input path, model, filter, or figure exists. When the project needs to be shared, reviewed, revisited, or moved to another machine, that missing context becomes expensive.</p>
<p>A Quarto document helps because it keeps the reasoning close to the code. The explanation, the executable code, and the outputs live in one place. The analysis is no longer a script plus a separate set of notes plus a folder of copied figures. It is a document that can be read, rendered, and inspected.</p>
<p>There is also a practical benefit that is easy to underestimate: consolidation. A common research workflow spreads the work across several tools: code in an editor, tables and charts in a spreadsheet, narrative in a document editor, and a manual copy-paste step connecting them all. Every time the data changes, the cycle repeats.</p>
<p>Quarto collapses much of that work into a single source. Tables and visualizations are generated directly from the code and appear in the document automatically. When the data changes, a render updates the outputs. There is no figure to re-export by hand and no table to manually reconcile.</p>
<p>This does not mean that every project should remain a single document forever. That would be too strong a claim. As a project grows, reusable functions may belong in <code>R/</code>, helper scripts may belong in <code>scripts/</code>, and long-running computation may need to move elsewhere. But as a starting point, the Quarto document gives the project a narrative spine.</p>
<p>The goal is not purity. The goal is to keep the analysis understandable, reproducible, and easy to move.</p>
</section>
<section id="create-the-document-with-toolero" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="create-the-document-with-toolero"><span class="header-section-number">4</span> Create the document with toolero</h2>
<p>The <code>toolero</code> package includes <code>create_qmd()</code>, a function that scaffolds a Quarto analysis document with reproducible project conventions in mind.</p>
<p>First, load <code>toolero</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(toolero)</span></code></pre></div></div>
<p>From inside the project root, create the analysis document:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_qmd</span>(</span>
<span id="cb6-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>,</span>
<span id="cb6-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"notebook2cluster-p1-start-with-the-document.qmd"</span></span>
<span id="cb6-4">)</span></code></pre></div></div>
<p>This does more than create an empty <code>.qmd</code> file. It gives us a starting document and, by default, sets up the mechanism that helps prevent code drift: a post-render <code>purl()</code> workflow that extracts the R code from the document into a companion <code>.R</code> script.</p>
<p>The important relationship is one-way:</p>
<pre class="text"><code>edit the .qmd  -&gt; render the document  -&gt; derive the .R script</code></pre>
<p>The <code>.qmd</code> is the file we maintain. The <code>.R</code> script is derived from it.</p>
<p>That is the design choice that matters. If we later run the script from the command line, inside a container, or as part of a CHTC job, we want confidence that the script reflects the current document. We do not want two parallel versions of the analysis that have to be kept in sync by memory.</p>
</section>
<section id="use-yaml-to-make-repeated-setup-less-repetitive" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="use-yaml-to-make-repeated-setup-less-repetitive"><span class="header-section-number">5</span> Use YAML to make repeated setup less repetitive</h2>
<p>A Quarto document begins with YAML metadata. At its simplest, YAML records the title, format, and other rendering options for the document. In practice, it often becomes a place where repeated setup accumulates: author name, affiliation, table of contents settings, theme, CSS, project-specific parameters, and other conventions.</p>
<p>This is one of the reasons <code>create_qmd()</code> is useful. If you regularly create documents with the same author information, institutional metadata, preferred options, or parameters, you should not have to rebuild those fields by hand every time.</p>
<p><code>create_qmd()</code> can use a YAML configuration file to pre-populate the document header:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_qmd</span>(</span>
<span id="cb8-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path      =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>,</span>
<span id="cb8-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"notebook2cluster-p1-start-with-the-document.qmd"</span>,</span>
<span id="cb8-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yaml_data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path/to/my-config.yml"</span></span>
<span id="cb8-5">)</span></code></pre></div></div>
<p>For this post, the key parameter is the input data file:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">params</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb9-2"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data_file</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw/palmer-penguins.csv"</span></span></code></pre></div></div>
<p>That parameter gives the document a default input when it is rendered with Quarto. Later, when the same code is run with <code>Rscript</code>, the input can be supplied as a command-line argument instead.</p>
<p>This is the beginning of portability. The same analysis can be run in more than one context without editing the code each time.</p>
</section>
<section id="before-we-write-the-analysis" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="before-we-write-the-analysis"><span class="header-section-number">6</span> Before we write the analysis</h2>
<p>Before writing analysis code, it is worth naming the constraints we want the document to satisfy.</p>
<p>The document should:</p>
<ul>
<li>read the original dataset from <code>data-raw/palmer-penguins.csv</code>;</li>
<li>write tabular outputs to <code>results/</code>;</li>
<li>write visual outputs to <code>plots/</code>;</li>
<li>behave correctly when rendered as a Quarto document;</li>
<li>behave correctly when run as a standalone <code>.R</code> script;</li>
<li>make the later transition to containerized and scheduled execution easier.</li>
</ul>
<p>Those are not advanced requirements. They are the normal requirements of a project that may eventually leave your laptop.</p>
<p>The safest time to account for them is now.</p>
</section>
<section id="a-minimal-analysis-thread" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="a-minimal-analysis-thread"><span class="header-section-number">7</span> A minimal analysis thread</h2>
<p>The analysis in this post is intentionally small. We will use the Palmer Penguins dataset to calculate summary statistics for flipper length and visualize the distribution of flipper length by species.</p>
<p>The analysis itself is not the point. The pattern is the point.</p>
<p>A small analysis lets us focus on the structure:</p>
<div class="cell" data-layout-align="default">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode default code-with-copy"><code class="sourceCode default"><span id="cb10-1">flowchart LR</span>
<span id="cb10-2">  A[Load libraries&lt;br&gt;and data] --&gt; B[Prepare data]</span>
<span id="cb10-3">  B --&gt; C[Calculate summaries]</span>
<span id="cb10-4">  C --&gt; D[Render table]</span>
<span id="cb10-5">  C --&gt; E[Render plot]</span>
<span id="cb10-6">  D --&gt; F[Save outputs]</span>
<span id="cb10-7">  E --&gt; F</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-mermaid" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mermaid-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<pre class="mermaid mermaid-js" data-label="fig-mermaid">flowchart LR
  A[Load libraries&lt;br&gt;and data] --&gt; B[Prepare data]
  B --&gt; C[Calculate summaries]
  C --&gt; D[Render table]
  C --&gt; E[Render plot]
  D --&gt; F[Save outputs]
  E --&gt; F
</pre>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mermaid-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Analysis workflow
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;1 gives the bird’s-eye view. We load the data, compute summaries, render outputs, and save the deliverables in predictable locations.</p>
<p>That final step matters. A result printed to the screen may be useful during exploration, but a reproducible workflow needs files that can be inspected, shared, archived, or retrieved after a job runs somewhere else.</p>
</section>
<section id="resolve-inputs-across-execution-contexts" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="resolve-inputs-across-execution-contexts"><span class="header-section-number">8</span> Resolve inputs across execution contexts</h2>
<p>One of the subtle challenges in this workflow is avoiding code drift across execution contexts.</p>
<p>It is very easy to begin with one version of the logic for interactive work in RStudio, introduce a slightly different version for <code>quarto render</code>, and eventually add another version for <code>Rscript</code> when the analysis needs to run headlessly. Over time, those entry points can drift apart. A path gets updated in one place but not another. A parameter is handled differently. Behavior that worked locally no longer matches the rendered or scheduled version.</p>
<p>The result is duplicated logic and a project that becomes harder to trust.</p>
<p>The code below keeps the input resolution in one place. In an interactive session, the data path is convenient for local development. In a Quarto render, the path comes from the YAML <code>params</code> block. In an <code>Rscript</code> call, the path comes from the command-line argument, which is the pattern a job scheduler can use later.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (&lt;http://conflicted.r-lib.org/&gt;) to force all conflicts to become errors</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gt)</span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(toolero)</span>
<span id="cb13-3"></span>
<span id="cb13-4">context <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detect_execution_context</span>()</span>
<span id="cb13-5"></span>
<span id="cb13-6">args <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">commandArgs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trailingOnly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb13-7"></span>
<span id="cb13-8">data_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">switch</span>(context,</span>
<span id="cb13-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interactive =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw/palmer-penguins.csv"</span>,</span>
<span id="cb13-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quarto      =</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data_file,</span>
<span id="cb13-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rscript     =</span> args[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb13-12">)</span>
<span id="cb13-13"></span>
<span id="cb13-14">is_rscript <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">identical</span>(context, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rscript"</span>)</span>
<span id="cb13-15">should_render_outputs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_rscript</span>
<span id="cb13-16"></span>
<span id="cb13-17">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(data_file)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Rows: 344 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): species, island, sex
dbl (5): bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, year

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.</code></pre>
</div>
</div>
<p>The important thing is that <code>data_file</code> is resolved once. The rest of the analysis does not need to know whether the code was run interactively, rendered as a document, or called from the command line.</p>
<p>That is a small design decision, but it has a long reach. It is one of the things that makes the <code>.qmd</code> and the derived <code>.R</code> script portable.</p>
</section>
<section id="tabular-results" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="tabular-results"><span class="header-section-number">9</span> Tabular results</h2>
<p>We can now calculate a small set of summary statistics for flipper length across the three penguin species.</p>
<p>The code below groups the data by species and computes the minimum, maximum, mean, and standard deviation of <code>flipper_length_mm</code>. The resulting data frame is then formatted as a table with <code>gt</code> when the document is rendered or run interactively.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">flipper_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb15-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_flipper_length  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_flipper_length  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_flipper_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_flipper_length   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb15-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb15-9">  )</span>
<span id="cb15-10"></span>
<span id="cb15-11">flipper_stats_tbl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> flipper_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb15-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tab_header</span>(</span>
<span id="cb15-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flipper Length by Species"</span>,</span>
<span id="cb15-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Summary statistics in millimeters"</span></span>
<span id="cb15-17">  )</span>
<span id="cb15-18"></span>
<span id="cb15-19"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (should_render_outputs) flipper_stats_tbl</span></code></pre></div></div>
<div id="tbl-flipper-summary" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-flipper-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Summary statistics for flipper length by species
</figcaption>
<div aria-describedby="tbl-flipper-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<div id="epfppdzhwt" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#epfppdzhwt table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#epfppdzhwt thead, #epfppdzhwt tbody, #epfppdzhwt tfoot, #epfppdzhwt tr, #epfppdzhwt td, #epfppdzhwt th {
  border-style: none;
}

#epfppdzhwt p {
  margin: 0;
  padding: 0;
}

#epfppdzhwt .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#epfppdzhwt .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#epfppdzhwt .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#epfppdzhwt .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#epfppdzhwt .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#epfppdzhwt .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#epfppdzhwt .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#epfppdzhwt .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#epfppdzhwt .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#epfppdzhwt .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#epfppdzhwt .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#epfppdzhwt .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#epfppdzhwt .gt_spanner_row {
  border-bottom-style: hidden;
}

#epfppdzhwt .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#epfppdzhwt .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#epfppdzhwt .gt_from_md > :first-child {
  margin-top: 0;
}

#epfppdzhwt .gt_from_md > :last-child {
  margin-bottom: 0;
}

#epfppdzhwt .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#epfppdzhwt .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#epfppdzhwt .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#epfppdzhwt .gt_row_group_first td {
  border-top-width: 2px;
}

#epfppdzhwt .gt_row_group_first th {
  border-top-width: 2px;
}

#epfppdzhwt .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#epfppdzhwt .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#epfppdzhwt .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#epfppdzhwt .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#epfppdzhwt .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#epfppdzhwt .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#epfppdzhwt .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#epfppdzhwt .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#epfppdzhwt .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#epfppdzhwt .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#epfppdzhwt .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#epfppdzhwt .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#epfppdzhwt .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#epfppdzhwt .gt_left {
  text-align: left;
}

#epfppdzhwt .gt_center {
  text-align: center;
}

#epfppdzhwt .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#epfppdzhwt .gt_font_normal {
  font-weight: normal;
}

#epfppdzhwt .gt_font_bold {
  font-weight: bold;
}

#epfppdzhwt .gt_font_italic {
  font-style: italic;
}

#epfppdzhwt .gt_super {
  font-size: 65%;
}

#epfppdzhwt .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#epfppdzhwt .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#epfppdzhwt .gt_indent_1 {
  text-indent: 5px;
}

#epfppdzhwt .gt_indent_2 {
  text-indent: 10px;
}

#epfppdzhwt .gt_indent_3 {
  text-indent: 15px;
}

#epfppdzhwt .gt_indent_4 {
  text-indent: 20px;
}

#epfppdzhwt .gt_indent_5 {
  text-indent: 25px;
}

#epfppdzhwt .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#epfppdzhwt div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table cell caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading header">
<td colspan="5" class="gt_heading gt_title gt_font_normal">Flipper Length by Species</td>
</tr>
<tr class="gt_heading even">
<td colspan="5" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Summary statistics in millimeters</td>
</tr>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="min_flipper_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper_length</th>
<th id="max_flipper_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper_length</th>
<th id="mean_flipper_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper_length</th>
<th id="sd_flipper_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper_length</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="min_flipper_length">172</td>
<td class="gt_row gt_right" headers="max_flipper_length">210</td>
<td class="gt_row gt_right" headers="mean_flipper_length">190</td>
<td class="gt_row gt_right" headers="sd_flipper_length">7</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="min_flipper_length">178</td>
<td class="gt_row gt_right" headers="max_flipper_length">212</td>
<td class="gt_row gt_right" headers="mean_flipper_length">196</td>
<td class="gt_row gt_right" headers="sd_flipper_length">7</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="min_flipper_length">203</td>
<td class="gt_row gt_right" headers="max_flipper_length">231</td>
<td class="gt_row gt_right" headers="mean_flipper_length">217</td>
<td class="gt_row gt_right" headers="sd_flipper_length">6</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
</figure>
</div>
</div>
<p>Table&nbsp;1 shows a familiar pattern in the Palmer Penguins data: Gentoo penguins have longer flippers than Adelie and Chinstrap penguins. The table is useful because it makes the numerical pattern explicit.</p>
<p>For the long game, there is another point worth noticing. The object <code>flipper_stats</code> is not only something we can print in the document. It is also something we can save as a file.</p>
<p>That distinction matters when the analysis runs outside the document.</p>
</section>
<section id="visualizing-distributions" class="level2" data-number="10">
<h2 data-number="10" class="anchored" data-anchor-id="visualizing-distributions"><span class="header-section-number">10</span> Visualizing distributions</h2>
<p>A table summarizes the pattern, but a plot makes the distribution easier to inspect.</p>
<p>The code below visualizes flipper length across species using three complementary layers: a violin plot for the distribution, a boxplot for the summary, and jittered points for the individual observations.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(</span>
<span id="cb16-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> species,</span>
<span id="cb16-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> flipper_length_mm,</span>
<span id="cb16-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> species,</span>
<span id="cb16-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> species</span>
<span id="cb16-7">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_violin</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outlier.shape =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_jitter</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_brewer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Set2"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_brewer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Set2"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb16-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flipper Length by Species"</span>,</span>
<span id="cb16-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of flipper length in millimeters"</span>,</span>
<span id="cb16-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x        =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb16-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flipper length (mm)"</span>,</span>
<span id="cb16-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data: Palmer Penguins"</span></span>
<span id="cb16-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb16-22"></span>
<span id="cb16-23"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (should_render_outputs) p</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_ydensity()`).</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_boxplot()`).</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).</code></pre>
</div>
<div class="cell-output-display">
<div id="fig-flipper-distribution" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-flipper-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://erwinlares.com/posts/2026-07-01-notebook-2-cluster-1-continue-with-the-document/index_files/figure-html/fig-flipper-distribution-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-flipper-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Distribution of flipper length by species
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;2 shows the same general result as the table, but with more texture. Adelie and Chinstrap penguins overlap more strongly, while Gentoo penguins are visibly larger by this measure. The point is not that this is a complicated analysis. The point is that the document lets us keep the explanation, code, table, and plot together.</p>
</section>
<section id="save-analysis-outputs" class="level2" data-number="11">
<h2 data-number="11" class="anchored" data-anchor-id="save-analysis-outputs"><span class="header-section-number">11</span> Save analysis outputs</h2>
<p>In many analyses, the deliverables are not only objects printed to the screen. They are files saved for later use: summary tables, plots, model objects, logs, or other artifacts that a collaborator, manuscript, or later workflow will need.</p>
<p>For this project, the folder conventions were established in Part 0:</p>
<pre class="text"><code>results/   # tabular or non-visual outputs
plots/     # visual outputs</code></pre>
<p>The code below saves the summary statistics to <code>results/</code> and the plot to <code>plots/</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">results_dir <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"results"</span></span>
<span id="cb21-2">plots_dir <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plots"</span></span>
<span id="cb21-3"></span>
<span id="cb21-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (dir <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(results_dir, plots_dir)) {</span>
<span id="cb21-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.exists</span>(dir)) {</span>
<span id="cb21-6">    cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_alert_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Creating directory: {.path {dir}}"</span>)</span>
<span id="cb21-7"></span>
<span id="cb21-8">    dir_created <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(dir, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb21-9"></span>
<span id="cb21-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>dir_created) {</span>
<span id="cb21-11">      cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_abort</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Could not create directory: {.path {dir}}"</span>)</span>
<span id="cb21-12">    }</span>
<span id="cb21-13">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb21-14">    cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_alert_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Using existing directory: {.path {dir}}"</span>)</span>
<span id="cb21-15">  }</span>
<span id="cb21-16">}</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ Using existing directory: 'results'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ Using existing directory: 'plots'</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">csv_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.path</span>(results_dir, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper-stats.csv"</span>)</span>
<span id="cb24-2">png_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.path</span>(plots_dir, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper-length-by-species.png"</span>)</span>
<span id="cb24-3"></span>
<span id="cb24-4">cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_alert_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Writing summary statistics to {.path {csv_file}}"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ Writing summary statistics to 'results/flipper-stats.csv'</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1">readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(flipper_stats, csv_file)</span>
<span id="cb26-2"></span>
<span id="cb26-3">cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_alert_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Saving plot to {.path {png_file}}"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>ℹ Saving plot to 'plots/flipper-length-by-species.png'</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1">ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggsave</span>(</span>
<span id="cb28-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename =</span> png_file,</span>
<span id="cb28-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot     =</span> p,</span>
<span id="cb28-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width    =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb28-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height   =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb28-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpi      =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span></span>
<span id="cb28-7">)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_ydensity()`).</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_boxplot()`).</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">cli<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cli_alert_success</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Results saved successfully."</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Results saved successfully.</code></pre>
</div>
</div>
<p>This is a modest step, but it is a useful habit. The script does not assume that a person will manually create output folders before running it. It checks for the directories it needs and writes deliverables to predictable locations.</p>
<p>That matters later, when the same code runs without anyone watching it.</p>
</section>
<section id="derive-the-runnable-r-script" class="level2" data-number="12">
<h2 data-number="12" class="anchored" data-anchor-id="derive-the-runnable-r-script"><span class="header-section-number">12</span> Derive the runnable R script</h2>
<p>When the analysis needs to run at scale, the document-rendering overhead may be unnecessary. At that point, we want the code, not the narrative.</p>
<p>This is where <code>create_qmd()</code> does more than create a blank Quarto document.</p>
<p>By default, <code>create_qmd()</code> can set up the project so that rendering the <code>.qmd</code> also derives a standalone <code>.R</code> script from the document. That behavior is controlled by the <code>use_purl</code> argument.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_qmd</span>(</span>
<span id="cb34-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>,</span>
<span id="cb34-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"notebook2cluster-p1-start-with-the-document.qmd"</span>,</span>
<span id="cb34-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_purl =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb34-5">)</span></code></pre></div></div>
<p>With <code>use_purl = TRUE</code>, <code>toolero</code> creates the pieces needed for an automatic post-render workflow. The project gets a <code>_quarto.yml</code> file that registers a post-render hook, and that hook runs a <code>purl.R</code> script after the document renders.</p>
<p>Conceptually, the workflow looks like this:</p>
<pre class="text"><code>render the .qmd
  -&gt; Quarto reads _quarto.yml
      -&gt; post-render runs purl.R
          -&gt; purl.R derives the companion .R script</code></pre>
<p>The result is the same relationship we want for the long game:</p>
<pre class="text"><code>notebook2cluster-p1-start-with-the-document.qmd
  -&gt; notebook2cluster-p1-start-with-the-document.R</code></pre>
<p>You maintain the <code>.qmd</code>. The <code>.R</code> script is regenerated from it.</p>
<p>Under the hood, the post-render script relies on <code>knitr::purl()</code>, which extracts R code chunks from a literate document and writes them to a standalone script. The source template for that helper script lives in the <code>toolero</code> package at <code>inst/templates/purl.R</code>. When <code>create_qmd(use_purl = TRUE)</code> is called, <code>toolero</code> copies or writes the needed post-render helper into the project so the project can regenerate its own <code>.R</code> script when rendered.</p>
<p>The exact implementation detail is less important than the direction of authority:</p>
<pre class="text"><code>.qmd is maintained by the researcher
.R is derived by the project machinery</code></pre>
<p>That direction is what prevents code drift. If the document and the script are both edited by hand, they can become two similar but different analyses. If the script is derived from the document, the relationship is clearer: edit the document, render the document, regenerate the script.</p>
<p>The <code>.qmd</code> is the source of truth. The <code>.R</code> file is the derived artifact.</p>
</section>
<section id="prepare-for-job-sized-inputs" class="level2" data-number="13">
<h2 data-number="13" class="anchored" data-anchor-id="prepare-for-job-sized-inputs"><span class="header-section-number">13</span> Prepare for job-sized inputs</h2>
<p>At this point, we have a document that can render an analysis and save outputs. That is enough for a local workflow. It is not yet enough for a high-throughput workflow.</p>
<p>HTC becomes useful when a larger task can be split into many independent pieces. For this toy example, splitting by penguin species is not computationally necessary. It is useful because it illustrates the pattern we will need later: one input file per job.</p>
<p>In Part 0, we created <code>data/jobs/</code> for this future purpose. Now we can use it.</p>
<p><code>toolero::write_by_group()</code> splits a data frame by a grouping column, writes one CSV file per group, and optionally writes a manifest that records the files created.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1">toolero<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_by_group</span>(</span>
<span id="cb38-2">  data,</span>
<span id="cb38-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group_col  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span>,</span>
<span id="cb38-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output_dir =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/jobs"</span>,</span>
<span id="cb38-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">manifest   =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb38-6">)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Written "Adelie" (152 rows) to 'data/jobs/adelie.csv'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Written "Chinstrap" (68 rows) to 'data/jobs/chinstrap.csv'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Written "Gentoo" (124 rows) to 'data/jobs/gentoo.csv'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ Manifest written to 'data/jobs/manifest.csv'</code></pre>
</div>
</div>
<p>This gives the future submission workflow a set of job-sized inputs. Conceptually, the structure is now:</p>
<pre class="text"><code>data-raw/palmer-penguins.csv   # original input data
data/jobs/                     # split inputs for later jobs</code></pre>
<p>The raw data remains untouched. The job inputs are derived from it.</p>
<p>That distinction is worth preserving.</p>
</section>
<section id="run-the-derived-script-from-the-command-line" class="level2" data-number="14">
<h2 data-number="14" class="anchored" data-anchor-id="run-the-derived-script-from-the-command-line"><span class="header-section-number">14</span> Run the derived script from the command line</h2>
<p>Once the <code>.R</code> script has been generated and the data has been split into subsets, each subset can be processed independently by passing it as a command-line argument.</p>
<p>For example:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb44-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">Rscript</span> notebook2cluster-p1-start-with-the-document.R data/jobs/adelie.csv</span></code></pre></div></div>
<p>This is the same kind of call that a job scheduler can use later. At small scale, you run one command manually. At larger scale, a submit file runs the same script many times, each time with a different input file.</p>
<p>The fact that the same script can run in both situations is the point. The portability was built in earlier, when we resolved the input file based on the execution context.</p>
<p>When the time comes to scale, the transition should be a change in infrastructure, not a rewrite of the analysis.</p>
</section>
<section id="what-we-have-after-part-1" class="level2" data-number="15">
<h2 data-number="15" class="anchored" data-anchor-id="what-we-have-after-part-1"><span class="header-section-number">15</span> What we have after Part 1</h2>
<p>At the end of Part 1, the project has moved from a structured home to a structured analysis.</p>
<p>We now have:</p>
<ul>
<li>a Quarto document that explains the analysis;</li>
<li>a derived <code>.R</code> script that can run outside the document;</li>
<li>an input path that works across interactive, Quarto, and <code>Rscript</code> contexts;</li>
<li>a summary table saved under <code>results/</code>;</li>
<li>a plot saved under <code>plots/</code>;</li>
<li>job-sized input files saved under <code>data/jobs/</code>;</li>
<li>a pattern that can be containerized and eventually submitted to CHTC.</li>
</ul>
<p>The important thing is not that the Palmer Penguins analysis is complex. It is not. The important thing is that the project now has a shape that can move.</p>
</section>
<section id="what-comes-next" class="level2" data-number="16">
<h2 data-number="16" class="anchored" data-anchor-id="what-comes-next"><span class="header-section-number">16</span> What comes next</h2>
<p>In Part 2, we will turn to the software environment.</p>
<p>Running a script outside the document is one step. Running it somewhere other than your laptop is another. For that, the project needs a portable software environment: the right R version, the right package versions, and the system libraries those packages require.</p>
<p>That is the role of <code>containr</code>.</p>
<p>The project already has the pieces that make containerization easier: a stable project structure, a clear input path, a derived script, saved outputs, and an <code>renv.lock</code> file. In the next part, we will use those pieces to build a container image.</p>
<p>For now, the document is doing what we need it to do.</p>
<p>It explains the analysis for humans and produces a script that machines can run.</p>


</section>

 ]]></description>
  <category>data-science</category>
  <category>R</category>
  <category>linguistics</category>
  <category>pottery</category>
  <category>aikido</category>
  <category>brug</category>
  <category>personal</category>
  <category>productivity</category>
  <category>coding</category>
  <category>Quarto</category>
  <category>R</category>
  <category>reproducible research</category>
  <category>research workflow</category>
  <category>command line</category>
  <category>Rscript</category>
  <category>CHTC</category>
  <category>portable code</category>
  <category>data subsetting</category>
  <category>toolero</category>
  <guid>https://erwinlares.com/posts/2026-07-01-notebook-2-cluster-1-continue-with-the-document/</guid>
  <pubDate>Wed, 01 Jul 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Understanding curriculr</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-27-understanding-curriculr/</link>
  <description><![CDATA[ 




<p>curriculr is an R package for building academic CVs and résumés from an Excel workbook, rendered to PDF via Quarto’s Typst engine. The core idea is simple: you maintain your CV data in a structured <code>.xlsx</code> file, call <code>create_cv()</code>, and get a typeset PDF back. The package handles all the intermediate steps — reading and validating the workbook, resolving a visual theme, injecting values into a Quarto template, and iterating over your data rows to emit raw Typst markup.</p>
<section id="package-architecture" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="package-architecture"><span class="header-section-number">1</span> Package architecture</h2>
<p>The pipeline has two distinct phases. The first phase runs in your R session: it reads and validates data, resolves theme values, and writes a filled-in <code>CV.qmd</code> file by substituting sentinels in the package template. The second phase runs in a Quarto subprocess: the rendered document calls back into curriculr’s exported rendering functions to emit raw Typst blocks row by row.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-27-understanding-curriculr/CV Data Creation Pipeline-2026-06-29-213038.png" class="img-fluid figure-img"></p>
<figcaption>Curriculr at a glance</figcaption>
</figure>
</div>
<p>The dashed arrow from <code>quarto_render()</code> into the inner box is doing conceptual work: those functions are not called directly from <code>create_cv()</code>. They run inside the Quarto subprocess when <code>CV.qmd</code> executes its R chunks. The connection is through the sentinel-substituted template, not a direct R call chain.</p>
<hr>
</section>
<section id="the-two-modes-of-create_cv" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="the-two-modes-of-create_cv"><span class="header-section-number">2</span> The two modes of <code>create_cv()</code></h2>
<section id="scaffold-mode" class="level3" data-number="2.1">
<h3 data-number="2.1" class="anchored" data-anchor-id="scaffold-mode"><span class="header-section-number">2.1</span> Scaffold mode</h3>
<p>Scaffold mode is triggered by calling <code>create_cv()</code> with no arguments — that is, when <code>data = NULL</code>. It is designed for first-time setup. No rendering takes place.</p>
<p>What it does, step by step:</p>
<ol type="1">
<li>Resolves <code>getwd()</code> to an absolute path via <code>fs::path_abs()</code>.</li>
<li>Copies <code>inst/extdata/cv-data-template.xlsx</code> to the current working directory. If the file already exists and <code>overwrite = FALSE</code> (the default), it prints an informational message and skips the copy.</li>
<li>Copies <code>inst/extdata/placeholder.png</code> under the same logic.</li>
<li>Prints a three-step instruction list telling the user to fill in the workbook, replace the placeholder photo, and call <code>create_cv()</code> with <code>data</code> and <code>photo</code> arguments.</li>
<li>Returns the destination directory invisibly.</li>
</ol>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Scaffold mode — run from your project directory</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>()</span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ✔ Created /your/project/cv-data-template.xlsx</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ✔ Created /your/project/placeholder.png</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ℹ Next steps:</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   1. Open cv-data-template.xlsx and fill in the profile sheet.</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   2. Replace placeholder.png with your own profile photo.</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   3. Call create_cv(data = 'cv-data-template.xlsx', photo = 'your-photo.png').</span></span></code></pre></div></div>
</section>
<section id="render-mode" class="level3" data-number="2.2">
<h3 data-number="2.2" class="anchored" data-anchor-id="render-mode"><span class="header-section-number">2.2</span> Render mode</h3>
<p>Render mode is triggered when a path is supplied to <code>data</code>. It runs the full pipeline: read, resolve, write, render.</p>
<p><strong>Step 1 — Validate scalar arguments.</strong> <code>variant</code> and <code>use_icons</code> are both validated with <code>match.arg()</code> before anything else. Invalid values abort with a clear error.</p>
<p><strong>Step 2 — Resolve and validate paths.</strong> Both <code>data</code> and <code>photo</code> (if supplied) are converted to absolute paths via <code>fs::path_abs()</code>. The photo’s path relative to the output directory is computed with <code>fs::path_rel()</code> — this is what gets injected into the template, since the Quarto subprocess needs a relative path to the image from the <code>.qmd</code> file’s location. If <code>photo = NULL</code>, <code>photo_rel</code> is set to an empty string and the template renders a single-column header.</p>
<p><strong>Step 3 — Read the workbook.</strong> <code>read_cv_data()</code> loads the workbook with <code>openxlsx2</code>, applies per-sheet logic, filters section rows when <code>variant = "resume"</code>, sorts dated sheets in reverse chronological order, and returns a named list. See the workbook schema section below for what each sheet must contain.</p>
<p><strong>Step 4 — Resolve the theme.</strong> <code>.resolve_theme()</code> merges <code>cv$theme</code> (which is <code>NULL</code> if the workbook has no <code>theme</code> sheet) with the twelve built-in defaults from <code>.cv_theme_defaults()</code>. Any key present in the workbook overrides the default; missing keys fall back silently.</p>
<p><strong>Step 5 — Write <code>CV.qmd</code>.</strong> The package template at <code>inst/templates/CV.qmd</code> is read into a string, then a series of <code>gsub()</code> calls replace five sentinels:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Sentinel</th>
<th>Replaced with</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>__CURRICULR_DATA_PATH__</code></td>
<td>Absolute path to the workbook</td>
</tr>
<tr class="even">
<td><code>__CURRICULR_PHOTO_PATH__</code></td>
<td>Relative path to the photo, or <code>""</code></td>
</tr>
<tr class="odd">
<td><code>__CURRICULR_VARIANT__</code></td>
<td><code>"cv"</code> or <code>"resume"</code></td>
</tr>
<tr class="even">
<td><code>%%CURRICULR_FORMAT%%</code></td>
<td>YAML <code>format: typst:</code> block from <code>.build_format_block()</code></td>
</tr>
<tr class="odd">
<td><code>%%CURRICULR_THEME%%</code></td>
<td>Raw <code>{=typst}</code> style block from <code>.build_typst_theme_block()</code></td>
</tr>
</tbody>
</table>
<p>The filled-in <code>CV.qmd</code> is written to the same directory as the workbook.</p>
<p><strong>Step 6 — Render to PDF.</strong> <code>quarto::quarto_render()</code> is called with <code>output_format = "typst"</code>. The Quarto subprocess re-reads the workbook, calls the rendering functions described below, and produces the final PDF.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Render mode — full CV with photo</span></span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>(</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my_cv/cv-data.xlsx"</span>,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">photo =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my_cv/headshot.jpg"</span></span>
<span id="cb2-5">)</span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Résumé variant — only rows with include_in_resume checked</span></span>
<span id="cb2-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>(</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my_cv/cv-data.xlsx"</span>,</span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">photo       =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my_cv/headshot.jpg"</span>,</span>
<span id="cb2-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variant     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"resume"</span>,</span>
<span id="cb2-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output_file =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"resume.pdf"</span></span>
<span id="cb2-13">)</span>
<span id="cb2-14"></span>
<span id="cb2-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plain-text contact line, no icons</span></span>
<span id="cb2-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>(</span>
<span id="cb2-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data      =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my_cv/cv-data.xlsx"</span>,</span>
<span id="cb2-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_icons =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span></span>
<span id="cb2-19">)</span></code></pre></div></div>
<hr>
</section>
</section>
<section id="the-workbook-schema" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="the-workbook-schema"><span class="header-section-number">3</span> The workbook schema</h2>
<p>The workbook is the single source of truth for all CV content. It is an <code>.xlsx</code> file with a fixed set of control sheets and any number of user-defined section sheets.</p>
<p><strong>Control sheets</strong> (reserved names, handled with special logic in <code>read_cv_data()</code>):</p>
<ul>
<li><code>profile</code> — two columns: <code>field</code> and <code>value</code>. Each row is one scalar: <code>first_name</code>, <code>last_name</code>, <code>email</code>, <code>website</code>, <code>github</code>, <code>linkedin</code>, <code>phone</code>, <code>address</code>, <code>profile_statement</code>. Returned as a named character vector.</li>
<li><code>sections</code> — the render-order manifest. Columns include <code>section</code> (matches the sheet name exactly), <code>label</code> (display heading), <code>title_col</code>, <code>org_col</code>, <code>detail_col</code>, <code>date_fun</code>, and <code>where_col</code>. Row order controls the order sections appear in the rendered CV.</li>
<li><code>theme</code> — two columns: <code>key</code> and <code>value</code>. Twelve recognized keys covering fonts, colors, page size, and margins. Optional — absent sheet triggers built-in defaults.</li>
<li><code>readme</code> — documentation sheet, skipped entirely by <code>read_cv_data()</code>.</li>
</ul>
<p><strong>Section sheets</strong> — one sheet per CV section (e.g.&nbsp;<code>education</code>, <code>experience</code>, <code>publications</code>). Standard column spine:</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Column</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>title</code></td>
<td>Main entry label</td>
</tr>
<tr class="even">
<td><code>unit</code></td>
<td>Organization or venue</td>
</tr>
<tr class="odd">
<td><code>startMonth</code></td>
<td>Start month</td>
</tr>
<tr class="even">
<td><code>startYear</code></td>
<td>Start year (used for reverse-chronological sort)</td>
</tr>
<tr class="odd">
<td><code>endMonth</code></td>
<td>End month (<code>"present"</code> supported)</td>
</tr>
<tr class="even">
<td><code>endYear</code></td>
<td>End year</td>
</tr>
<tr class="odd">
<td><code>where</code></td>
<td>Location</td>
</tr>
<tr class="even">
<td><code>detail</code></td>
<td>Additional context line</td>
</tr>
<tr class="odd">
<td><code>include_in_resume</code></td>
<td>Boolean — controls résumé filtering</td>
</tr>
</tbody>
</table>
<p>The <code>include_in_resume</code> column is consumed by <code>read_cv_data()</code> and dropped before data reaches the rendering pipeline. New sections can be added programmatically with <code>add_section()</code>.</p>
<hr>
</section>
<section id="inside-cv.qmd-the-rendering-pipeline" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="inside-cv.qmd-the-rendering-pipeline"><span class="header-section-number">4</span> Inside <code>CV.qmd</code>: the rendering pipeline</h2>
<p>Once Quarto launches the subprocess, the <code>.qmd</code> file runs four R chunks that call back into curriculr’s exported functions.</p>
<p>The <strong>setup chunk</strong> calls <code>read_cv_data()</code> again with the injected path and variant, reconstituting the <code>cv</code> list inside the subprocess.</p>
<p>The <strong>header chunk</strong> calls <code>cv_contact_line()</code> to build the Typst-formatted contact line, then emits a two-column photo/name/contact grid (when <code>photo</code> is non-empty) or a single-column header (when it is). All profile strings are passed through <code>typst_escape()</code> before being spliced into Typst.</p>
<p>The <strong>sections chunk</strong> iterates over the rows of <code>cv$sections</code> in order. For each section it calls <code>cv_section()</code> to emit the heading, then <code>cv_render_section()</code> to emit the entries. The column names and <code>date_fun</code> token are read directly from <code>cv$sections</code>, so section-level formatting is controlled entirely from the workbook.</p>
<section id="the-builderprinter-split" class="level3" data-number="4.1">
<h3 data-number="4.1" class="anchored" data-anchor-id="the-builderprinter-split"><span class="header-section-number">4.1</span> The builder/printer split</h3>
<p><code>cv_render_section()</code> is the printer: it calls <code>cat()</code> and returns <code>invisible(NULL)</code>. It is not directly testable because its output goes to stdout.</p>
<p><code>.build_section_blocks()</code> is the builder: it does the real work — iterating over rows, calling <code>.cv_entry()</code> for each one, returning a character vector of Typst blocks. Because it returns a value rather than printing, it can be tested directly with <code>testthat</code> without capturing stdout.</p>
<p>This pattern — builder builds, printer prints — is used consistently across curriculr and <code>arborize</code>.</p>
<hr>
</section>
</section>
<section id="function-reference" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="function-reference"><span class="header-section-number">5</span> Function reference</h2>
<section id="exported-functions" class="level3" data-number="5.1">
<h3 data-number="5.1" class="anchored" data-anchor-id="exported-functions"><span class="header-section-number">5.1</span> Exported functions</h3>
<p><strong><code>create_cv(data, photo, output_file, overwrite, variant, use_icons)</code></strong> The main entry point. Dispatches to scaffold mode when <code>data = NULL</code>, render mode otherwise. In render mode it orchestrates the full pipeline: validate, read, resolve theme, write template, render. Returns the destination directory (scaffold) or PDF path (render) invisibly.</p>
<p><strong><code>read_cv_data(path, variant)</code></strong> Reads all sheets from a curriculr-formatted <code>.xlsx</code> workbook and returns a named list. The <code>profile</code> and <code>theme</code> elements are named character vectors; all section elements are data frames sorted in reverse chronological order by <code>startYear</code>. The <code>include_in_resume</code> column is used for filtering when <code>variant = "resume"</code> and is then dropped. The <code>readme</code> sheet is skipped entirely.</p>
<p><strong><code>add_section(workbook, section, label, date_fun, title_col, org_col, detail_col, where_col, overwrite)</code></strong> Adds a new sheet to an existing workbook and registers it in the <code>sections</code> control sheet. Writes the standard nine-column spine (<code>title</code>, <code>unit</code>, <code>startMonth</code>, <code>startYear</code>, <code>endMonth</code>, <code>endYear</code>, <code>where</code>, <code>detail</code>, <code>include_in_resume</code>) and adds a TRUE/FALSE dropdown validation on the <code>include_in_resume</code> column. Modifies the workbook in place.</p>
<p><strong><code>cv_contact_line(profile, use_icons)</code></strong> Assembles the Typst-formatted contact line for the CV header. When <code>use_icons = "fontawesome"</code>, known fields (<code>email</code>, <code>website</code>, <code>github</code>, <code>linkedin</code>, <code>phone</code>) are rendered as <code>#fa-icon("...")</code> calls with their display text. Unknown fields fall back to plain text with a warning. When <code>use_icons = "none"</code>, all fields render as plain text separated by a middle dot. <code>github</code> and <code>linkedin</code> values are expanded to full URLs regardless of whether the workbook stores bare usernames or full URLs.</p>
<p><strong><code>cv_section(title)</code></strong> Emits a raw <code>{=typst}</code> code block for a section heading. The first letter is rendered in the accent color; the remainder in the dark color. A horizontal rule in a light gray fills the rest of the line, implemented as a two-column <code>#grid</code> in Typst.</p>
<p><strong><code>cv_render_section(data, title_col, org_col, detail_col, date_fun, where_col)</code></strong> The printer half of the builder/printer split. Calls <code>.build_section_blocks()</code> and passes the result to <code>cat()</code>. Intended to be called inside a Quarto chunk with <code>results = "asis"</code>. Returns <code>invisible(NULL)</code>.</p>
<p><strong><code>resolve_date_fun(token)</code></strong> Maps a string token to a date-formatting function. Supported tokens: <code>"date"</code> (full month+year range via <code>.cv_date_range()</code>), <code>"year"</code> (year range via <code>.cv_year_range()</code>), <code>"month_year"</code> (start month and year only), <code>"year_only"</code> (start year only), <code>"none"</code> (returns <code>NULL</code>, date omitted). Unknown tokens emit a <code>cli_warn()</code> and return <code>NULL</code>.</p>
<p><strong><code>typst_escape(x)</code></strong> Escapes a character value for safe use in Typst markup. Strips HTML <code>&lt;br&gt;</code> tags, collapses repeated whitespace, escapes the characters Typst treats as markup (<code>#</code>, <code>$</code>, <code>%</code>, <code>&amp;</code>, <code>~</code>, <code>_</code>, <code>^</code>, <code>{</code>, <code>}</code>, <code>[</code>, <code>]</code>, <code>@</code>), and trims leading/trailing whitespace. The <code>@</code> is included because Typst interprets bare email addresses as label references.</p>
<hr>
</section>
<section id="internal-helpers" class="level3" data-number="5.2">
<h3 data-number="5.2" class="anchored" data-anchor-id="internal-helpers"><span class="header-section-number">5.2</span> Internal helpers</h3>
<p><strong><code>.resolve_theme(theme)</code></strong> Merges a user-supplied theme vector (or <code>NULL</code>) with the twelve built-in defaults from <code>.cv_theme_defaults()</code>. Any key present in the workbook theme overrides the default; absent or empty keys are filled from defaults silently. Returns a fully-populated named character vector with all twelve keys present.</p>
<p><strong><code>.cv_theme_defaults()</code></strong> Returns the twelve built-in theme defaults as a named character vector: <code>font_family</code> (<code>"Lato"</code>), <code>font_size</code> (<code>"8.8pt"</code>), <code>body_color</code>, <code>line_leading</code>, <code>accent_color</code> (<code>"#c5050c"</code> — Badger Red), <code>dark_color</code>, <code>bodygray_color</code>, <code>lightgray_color</code>, <code>rulegray_color</code>, <code>papersize</code> (<code>"us-letter"</code>), <code>margin_x</code>, <code>margin_y</code>.</p>
<p><strong><code>.build_format_block(theme)</code></strong> Constructs the <code>format: typst:</code> YAML block injected at the <code>%%CURRICULR_FORMAT%%</code> sentinel. Pulls <code>papersize</code>, <code>margin_x</code>, and <code>margin_y</code> from the resolved theme.</p>
<p><strong><code>.build_typst_theme_block(theme, use_icons)</code></strong> Constructs the raw <code>{=typst}</code> code block injected at the <code>%%CURRICULR_THEME%%</code> sentinel. Sets <code>#set text()</code> and <code>#set par()</code> and defines five Typst color variables (<code>accent</code>, <code>dark</code>, <code>bodygray</code>, <code>lightgray</code>, <code>rulegray</code>). When <code>use_icons = "fontawesome"</code>, prepends the <code>#import "@preview/fontawesome:0.5.0": *</code> line.</p>
<p><strong><code>.build_section_blocks(data, title_col, org_col, detail_col, date_fun, where_col)</code></strong> The builder half of the builder/printer split. Iterates over each row of <code>data</code>, calling <code>.cv_entry()</code> for each one, and returns a character vector of Typst grid blocks — one element per row. Testable without stdout capture.</p>
<p><strong><code>.cv_entry(title, organization, detail, when, where)</code></strong> Produces a single raw <code>{=typst}</code> block for one CV entry. Runs all five arguments through <code>typst_escape()</code>, then emits a two-column <code>#grid</code>: left column holds title (semibold, dark) and organization+detail (smaller, gray, joined by an em dash); right column holds <code>when</code> and <code>where</code> (right-aligned, accent color, stacked with a hard line break). Empty fields are dropped via <code>nzchar()</code> so no blank lines or dangling em dashes appear.</p>
<p><strong><code>.cv_date_range(row)</code></strong> Formats a full date range from a one-row data frame using <code>startMonth</code>, <code>startYear</code>, <code>endMonth</code>, and <code>endYear</code>. Handles the <code>"present"</code> sentinel (case-insensitive) in <code>endMonth</code>. Called by <code>resolve_date_fun()</code> when token is <code>"date"</code>.</p>
<p><strong><code>.cv_year_range(row)</code></strong> Formats a year-only range from <code>startYear</code> and <code>endYear</code>. Returns just the start year when <code>endYear</code> is absent. Called by <code>resolve_date_fun()</code> when token is <code>"year"</code>.</p>
<p><strong><code>.cv_value(row, name, default)</code></strong> Safely extracts a named value from a one-row data frame. Returns <code>default</code> (empty string by default) when the column does not exist or the value is <code>NA</code>. Used throughout <code>.cv_entry()</code> and the date helpers.</p>
<p><strong><code>.fa_icon_map()</code></strong> Returns a named character vector mapping profile field names to their Font Awesome icon identifiers as used by the Typst <code>@preview/fontawesome</code> package. Currently maps <code>email → "envelope"</code>, <code>website → "globe"</code>, <code>github → "github"</code>, <code>linkedin → "linkedin"</code>, <code>phone → "phone"</code>.</p>
<p><strong><code>.coerce_col(col)</code></strong> Converts a column to character and normalizes the string <code>"NA"</code> (produced by <code>as.character(NA)</code>) back to <code>NA_character_</code>. Applied to every column of every sheet read by <code>read_cv_data()</code>.</p>
<p><strong><code>%||%(x, y)</code></strong> Null-coalescing operator. Returns <code>y</code> when <code>x</code> is <code>NULL</code>, zero-length, or all-<code>NA</code>. Used throughout the rendering helpers to provide safe fallbacks.</p>
</section>
</section>
<section id="sentinels-and-the-null-coalescing-operator" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="sentinels-and-the-null-coalescing-operator"><span class="header-section-number">6</span> Sentinels and the null-coalescing operator</h2>
<section id="sentinels" class="level3" data-number="6.1">
<h3 data-number="6.1" class="anchored" data-anchor-id="sentinels"><span class="header-section-number">6.1</span> Sentinels</h3>
<p>In curriculr, a sentinel is a placeholder string embedded in the <code>CV.qmd</code> template that <code>create_cv()</code> replaces at runtime with a real value using <code>gsub()</code>. They’re essentially markup that the template itself can’t know ahead of time — things that only become available when the user actually calls <code>create_cv()</code> with their specific paths, variant, and theme choices.</p>
<p>There are five of them:</p>
<ul>
<li><code>__CURRICULR_DATA_PATH__</code> — replaced with the absolute path to the user’s workbook</li>
<li><code>__CURRICULR_PHOTO_PATH__</code> — replaced with the relative path to the photo, or an empty string</li>
<li><code>__CURRICULR_VARIANT__</code> — replaced with <code>"cv"</code> or <code>"resume"</code></li>
<li><code>%%CURRICULR_FORMAT%%</code> — replaced with the full <code>format: typst:</code> YAML block built from the resolved theme</li>
<li><code>%%CURRICULR_THEME%%</code> — replaced with the raw <code>{=typst}</code> style block that sets fonts, colors, and optionally imports the Font Awesome package</li>
</ul>
<p>The two naming conventions (<code>__DOUBLE_UNDERSCORE__</code> vs <code>%%PERCENT_PERCENT%%</code>) are just a visual distinction between the two kinds of substitution: the underscore sentinels are scalar string values, while the percent sentinels are entire multi-line code blocks. It’s not enforced anywhere — just a readability convention.</p>
</section>
<section id="the-null-coalescing-operator" class="level3" data-number="6.2">
<h3 data-number="6.2" class="anchored" data-anchor-id="the-null-coalescing-operator"><span class="header-section-number">6.2</span> The <code>%||%</code> null-coalescing operator</h3>
<p>That’s <code>%||%</code>, the null-coalescing operator defined in <code>typst-helpers.R</code>. It’s a pretty common R idiom — you’ll find versions of it in rlang and several other packages — but curriculr defines its own rather than taking a dependency just for this.</p>
<p>The logic is:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">%||%</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, y) {</span>
<span id="cb3-2">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(x))) y <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> x</span>
<span id="cb3-3">}</span></code></pre></div></div>
<p>So it returns <code>y</code> when <code>x</code> is <code>NULL</code>, zero-length, or entirely <code>NA</code> — and returns <code>x</code> otherwise. It’s slightly more defensive than the rlang version, which only checks for <code>NULL</code>. The <code>all(is.na(x))</code> arm means it also catches columns that came back from Excel as a vector of <code>NA</code>s, which is a realistic edge case when a user leaves a field blank in the workbook.</p>
<p>In practice it shows up in <code>typst_escape()</code> and the date/value helpers as a safe fallback to an empty string, so that a missing profile field or an empty cell never causes a downstream error — it just silently becomes <code>""</code> and gets dropped by the <code>nzchar()</code> checks later in <code>.cv_entry()</code>.</p>
</section>
</section>
<section id="on-passing-raw-output" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="on-passing-raw-output"><span class="header-section-number">7</span> On passing raw output</h2>
<p>Here’s an example of what the raw output passed on can look like.</p>
<pre><code>```{=typst}
#grid(
  columns: (1fr, 1.68in),
  gutter: 0.65em,
  [
    #text(size: 9.15pt, weight: "semibold", fill: dark)[PhD in Linguistics]
    #text(size: 8.25pt, fill: bodygray)[University of Wisconsin--Madison — Spanish Phonetics and Phonology]
  ],
  [#align(right)[#text(size: 8.1pt, fill: accent)[2018 - 2024\nMadison, WI]]]
)
#v(0.36em)
```</code></pre>
<p>And a section heading looks like:</p>
<pre><code>```{=typst}
#v(0.58em)
#grid(
  columns: (auto, 1fr),
  gutter: 0.65em,
  align: horizon,
  [#text(size: 13.8pt, weight: "regular", fill: dark)[#text(fill: accent)[E]ducation]],
  [#line(length: 100%, stroke: 0.55pt + rulegray)]
)
#v(0.20em)
```</code></pre>
<hr>
<p>As for the two design choices — they’re actually solving the same underlying problem from different angles.</p>
<p><strong><code>{=typst}</code> blocks</strong> are Quarto’s “raw passthrough” syntax. Wrapping content in <code>```{=typst}</code> tells Quarto: don’t touch this, don’t interpret it as Markdown, just hand it directly to the Typst compiler as-is. Without that wrapper, Quarto would try to process the <code>#grid(...)</code> calls as Markdown and mangle them. It’s the same idea as <code>{=html}</code> or <code>{=latex}</code> raw blocks — you’re stepping outside Quarto’s rendering layer entirely and speaking directly to the target format.</p>
<p><strong><code>results = "asis"</code></strong> solves the R side of the same problem. Normally when an R chunk calls <code>cat()</code>, knitr wraps the output in a code block before passing it to Quarto. <code>results = "asis"</code> tells knitr to pass the output through verbatim, with no wrapping. So the chain is: <code>.cv_entry()</code> builds the string → <code>cat()</code> writes it → knitr passes it through raw → Quarto sees a <code>{=typst}</code> block → Typst compiles it. Remove either piece and the chain breaks — without <code>{=typst}</code> Quarto garbles the markup, without <code>results = "asis"</code> knitr wraps it in a fence and Quarto never sees raw Typst at all.</p>
<p>It’s a clean stack once you see it, but it does require knowing which layer each piece belongs to.</p>
</section>
<section id="using-curriculr" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="using-curriculr"><span class="header-section-number">8</span> Using curriculr</h2>
<p>Given how much machinery sits under the hood, it’s worth stepping back and describing what actually happens when you use curriculr, day to day. The internals covered above are there to explain <em>why</em> the package behaves the way it does; using it, mercifully, requires knowing very little of that.</p>
<section id="the-first-time" class="level3" data-number="8.1">
<h3 data-number="8.1" class="anchored" data-anchor-id="the-first-time"><span class="header-section-number">8.1</span> The first time</h3>
<p>The first time you touch curriculr, you’re in scaffold mode, whether you realize it or not. You call <code>create_cv()</code> with no arguments, curriculr copies two files into the working directory, a template workbook and a placeholder image, and prints a short list of next steps. Nothing renders yet.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(curriculr)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>()</span></code></pre></div></div>
<p>Those two artifacts are the whole of curriculr’s “installation” step, in a sense: an <code>.xlsx</code> workbook that will hold your CV content, and a stand-in photo you’re meant to replace with your own. Open the workbook, fill in the <code>profile</code> sheet (name, email, a line about yourself), then work through the section sheets. It may not be unreasonable to think of this as the only time you’ll look at R code before you have a working CV — the render itself needs just one more call:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>(</span>
<span id="cb7-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cv-data-template.xlsx"</span>,</span>
<span id="cb7-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">photo =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"your-photo.png"</span></span>
<span id="cb7-4">)</span></code></pre></div></div>
<p>That’s render mode — the same read, resolve, write, render pipeline covered earlier — and it’s the last time you need to think about R at all.</p>
</section>
<section id="keeping-it-current" class="level3" data-number="8.2">
<h3 data-number="8.2" class="anchored" data-anchor-id="keeping-it-current"><span class="header-section-number">8.2</span> Keeping it current</h3>
<p>Recall that curriculr treats the workbook, not the R session, as the single source of truth. In other words: once the CV exists, “updating your CV” and “editing the spreadsheet” are the same action. There’s no step where you write R code to add a job or a publication.</p>
<p>Say a new conference talk needs to go on the CV. You’d open the <code>presentations</code> sheet, add one row — title, venue, dates, and whatever <code>include_in_resume</code> value you want — and save the file:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 11%">
</colgroup>
<thead>
<tr class="header">
<th>title</th>
<th>unit</th>
<th>startMonth</th>
<th>startYear</th>
<th>endMonth</th>
<th>endYear</th>
<th>where</th>
<th>detail</th>
<th>include_in_resume</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Reproducible CVs with curriculr</td>
<td>BRUG Meetup</td>
<td>July</td>
<td>2026</td>
<td>July</td>
<td>2026</td>
<td>Madison, WI</td>
<td>Lightning talk on the package’s design</td>
<td>TRUE</td>
</tr>
</tbody>
</table>
<p>Then you rerun the same <code>create_cv()</code> call you used the first time, pointed at the same workbook:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_cv</span>(</span>
<span id="cb8-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cv-data-template.xlsx"</span>,</span>
<span id="cb8-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">photo =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"your-photo.png"</span></span>
<span id="cb8-4">)</span></code></pre></div></div>
<p>curriculr rereads the whole workbook, resolves the theme, rewrites <code>CV.qmd</code>, and rerenders — the new entry lands wherever <code>startYear</code> places it, since sections sort in reverse-chronological order automatically. You don’t reorder anything by hand, and you don’t touch <code>CV.qmd</code> directly (it’s regenerated fresh from the template every time, sentinels and all, so any manual edits to it wouldn’t survive the next render anyway).</p>
</section>
<section id="the-shape-of-it" class="level3" data-number="8.3">
<h3 data-number="8.3" class="anchored" data-anchor-id="the-shape-of-it"><span class="header-section-number">8.3</span> The shape of it</h3>
<p>Put the two paths together and the whole lifecycle looks like this:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-27-understanding-curriculr/curriculr-diagram.png" alt="a diagram showcasing how to use curricular" height="375" class="figure-img"></p>
<figcaption>Using <code>curriculr</code></figcaption>
</figure>
</div>
<p>Everything below “render mode” is the loop you’ll actually live in: edit a row, rerun the same call, get a new PDF. The scaffolding step happens exactly once per CV.</p>


</section>
</section>

 ]]></description>
  <category>data-science</category>
  <category>r</category>
  <category>linguistics</category>
  <category>pottery</category>
  <category>aikido</category>
  <category>brug</category>
  <category>personal</category>
  <category>reproducibility</category>
  <category>productivity</category>
  <category>coding</category>
  <guid>https://erwinlares.com/posts/2026-06-27-understanding-curriculr/</guid>
  <pubDate>Sat, 27 Jun 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>From the Notebook to the Cluster</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-24-notebook-2-cluster-0-start-with-the-project/</link>
  <description><![CDATA[ 
<div class="rci-header">
  <img src="https://erwinlares.com/posts/rci-banner.png" alt="Research Cyberinfrastructure at UW-Madison">
  <div class="rci-header-text">
    <span class="rci-title">Research Cyberinfrastructure</span>
    <span class="rci-subtitle">Division of Information Technology &nbsp;·&nbsp; UW–Madison</span>
  </div>
</div>




<section id="the-long-game" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="the-long-game"><span class="header-section-number">1</span> The long game</h2>
<p>This series is about moving a research coding project from a local machine to high-throughput computing. The destination matters: eventually, we want to run an analysis on the UW–Madison Center for High Throughput Computing (CHTC), where work that would be slow or repetitive on a laptop can be split into many independent jobs.</p>
<p>But the path to the cluster does not start with the cluster.</p>
<p>It starts with the project.</p>
<p>Before writing the analysis, before creating a Quarto document, before building a container image, and before submitting a job, we need to give the project a good home. A well-structured project makes local exploration easier today and makes containerization, command-line execution, and CHTC submission easier later.</p>
<p>That is the purpose of Part 0.</p>
<p>We know what we want to do: we have a dataset, the Palmer Penguins data, and we know we want to run an analysis on it. The analysis itself will come later. For now, the task is more basic. We need to decide what kind of project can hold this work, not only for the first script we write, but for the later stages of the workflow as well.</p>
<p>The rest of the series follows a deliberate sequence:</p>
<pre class="text"><code>Part 0  create the project home     -&gt; toolero::init_project()
Part 1  create the document/code    -&gt; toolero::create_qmd()
Part 2  containerize the project    -&gt; containr
Part 3  submit the first job        -&gt; submitr single-job workflow
Part 4  submit many jobs            -&gt; toolero::write_by_group() + submitr</code></pre>
<p>Each step has a clear intent. Each step should leave the project better prepared for the next one.</p>
</section>
<section id="why-project-structure-comes-first" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="why-project-structure-comes-first"><span class="header-section-number">2</span> Why project structure comes first</h2>
<p>Most research projects begin naively: a dataset, a script, and a question. The first few decisions feel small. A file goes on the Desktop. A script gets named <code>analysis-final.R</code>. A plot gets exported by hand. A package gets installed without recording the version. A collaborator receives a copy of the code by email.</p>
<p>Nothing breaks immediately.</p>
<p>That is why these habits are easy to underestimate.</p>
<p>The cost appears later, when the project needs to be shared, rerun, reviewed, containerized, or scaled-up and moved to another computing system. At that point, the project starts to depend on memory: where the raw data came from, which file is current, what package versions were installed, which script produced which result, and what changed between attempts.</p>
<p>A good project structure does not solve every problem. It does, however, remove a set of avoidable problems from the path. It gives the work a predictable home. It separates raw inputs from derived outputs. It records dependencies. It creates a place for scripts, documents, results, and supporting files. It also makes the project easier to explain to someone else, including your future self.</p>
<p>The best time to make these decisions is at the beginning, before the project has accumulated enough history to make reorganization painful.</p>
</section>
<section id="before-we-run-anything" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="before-we-run-anything"><span class="header-section-number">3</span> Before we run anything</h2>
<p>We are not going to create the project immediately.</p>
<p>First, we should decide what the project needs to support.</p>
<p>For this series, we know a few things in advance:</p>
<ul>
<li>our original input dataset will be named <code>palmer-penguins.csv</code>;</li>
<li>the original dataset should live in <code>data-raw/</code>;</li>
<li>later, we will split the dataset into job-sized inputs;</li>
<li>those split inputs should live in <code>data/jobs/</code>;</li>
<li>outputs should have a predictable home;</li>
<li>the project should track R package dependencies;</li>
<li>the project should track changes over time;</li>
<li>the structure should still make sense when the work moves from a laptop to CHTC.</li>
</ul>
<p>These decisions are small, but they are not arbitrary. They are early design choices that make later steps easier.</p>
<p>In other words, we are not only asking, “Where should I put this file today?” We are asking, “What structure will still make sense when this analysis needs to be rendered, scripted, containerized, and submitted as a job?”</p>
</section>
<section id="what-a-good-project-home-needs" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="what-a-good-project-home-needs"><span class="header-section-number">4</span> What a good project home needs</h2>
<p>For this workflow, a good research coding project needs:</p>
<ul>
<li>a project directory that contains the work;</li>
<li>a predictable folder structure;</li>
<li>a place for raw data;</li>
<li>a place for derived data and job inputs;</li>
<li>a place for results;</li>
<li>dependency tracking with <code>renv</code>;</li>
<li>version control with <code>git</code>;</li>
<li>room to add Quarto documents, scripts, containers, and CHTC submission files later.</li>
</ul>
<p>The exact folders matter less than the habit they represent: separate different kinds of files by role. Raw inputs are not the same as processed outputs. Scripts are not the same as results. Documentation is not the same as data.</p>
<p>The structure we create in this post is intentionally modest. It is not a rigid framework. It is a starting point that works well for many research workflows and can be customized as the project grows.</p>
</section>
<section id="installation" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="installation"><span class="header-section-number">5</span> Installation</h2>
<p>Before running any of the code below, you will need the <code>toolero</code> package. The current CRAN release can be installed in the usual way:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"toolero"</span>)</span></code></pre></div></div>
<p>However, this post reflects features introduced in <code>toolero 0.4.0</code>, which is currently available only in the development version. These features are scheduled to be pushed to CRAN at the end of July. In the meantime, install the development version from GitHub:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install.packages("pak")</span></span>
<span id="cb3-2">pak<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pak</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"erwinlares/toolero"</span>)</span></code></pre></div></div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>For the most current information on new features, breaking changes, and development status, see the package repository at <a href="https://github.com/erwinlares/toolero">github.com/erwinlares/toolero</a>.</p>
</div>
</div>
</section>
<section id="design-the-scaffold" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="design-the-scaffold"><span class="header-section-number">6</span> Design the scaffold</h2>
<p>The <code>toolero</code> package provides a project scaffolding function called <code>init_project()</code>. It creates a standard research project structure and, by default, initializes <code>renv</code> and <code>git</code>.</p>
<p>Once the package is loaded:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(toolero)</span></code></pre></div></div>
<p>The minimal version of the command looks like this:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Do not run this yet.</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We are first sketching the project we want to create.</span></span>
<span id="cb5-3"></span>
<span id="cb5-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb5-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmer-penguins-analysis"</span></span>
<span id="cb5-6">)</span></code></pre></div></div>
<p>This would create a project called <code>palmer-penguins-analysis</code> using the default scaffold.</p>
<section id="the-default-folder-structure" class="level3" data-number="6.1">
<h3 data-number="6.1" class="anchored" data-anchor-id="the-default-folder-structure"><span class="header-section-number">6.1</span> The default folder structure</h3>
<p>As of <code>0.4.0</code>, the default folder set follows conventions established by The Carpentries and UW-Madison Libraries: <code>data-raw/</code>, <code>data/</code>, <code>scripts/</code>, <code>output/figures/</code>, <code>output/tables/</code>, and <code>reports/</code>. This replaces the previous default set, so if you have used an earlier version of <code>toolero</code> the folder names will look a little different here.</p>
</section>
<section id="customizing-the-scaffold" class="level3" data-number="6.2">
<h3 data-number="6.2" class="anchored" data-anchor-id="customizing-the-scaffold"><span class="header-section-number">6.2</span> Customizing the scaffold</h3>
<p>We already know something specific about this project. Later in the series, we will split the Palmer Penguins dataset into separate inputs for many HTC jobs. Those files need a home. We can create that folder now.</p>
<p>That is what <code>custom_folders</code> is for. It lets us extend the default scaffold with folders that are specific to this project. Bare names add new folders; names prefixed with a minus sign<code>"-"</code> suppress a folder from the default set without affecting anything else.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Do not run this yet.</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This adds the future home for job-sized input files.</span></span>
<span id="cb6-3"></span>
<span id="cb6-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb6-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path           =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmer-penguins-analysis"</span>,</span>
<span id="cb6-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">custom_folders =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/jobs"</span></span>
<span id="cb6-7">)</span></code></pre></div></div>
<p>The important choice is not just the syntax. The important choice is the convention:</p>
<pre class="text"><code>data-raw/palmer-penguins.csv   # original input data
data/jobs/                     # future split inputs, one file per job
output/tables/                 # outputs from local or cluster runs</code></pre>
<p>We are not splitting the data in Part 0. That happens later. But we know where the project is going, so we create a place for the future job inputs now.</p>
</section>
<section id="config-driven-scaffolds" class="level3" data-number="6.3">
<h3 data-number="6.3" class="anchored" data-anchor-id="config-driven-scaffolds"><span class="header-section-number">6.3</span> Config-driven scaffolds</h3>
<p>For projects with a recurring or non-standard folder structure, <code>toolero 0.4.0</code> also introduces a <code>config</code> argument that lets you drive the entire folder set from a YAML file. <code>generate_project_config()</code> writes a skeleton config pre-filled with the standard folders; edit it to define your own layout and store it somewhere reusable.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Write a config skeleton to your home directory</span></span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generate_project_config</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"my-research-project.yml"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~"</span>)</span></code></pre></div></div>
<p>Then pass it to <code>init_project()</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb9-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmer-penguins-analysis"</span>,</span>
<span id="cb9-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">config =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~/my-research-project.yml"</span></span>
<span id="cb9-4">)</span></code></pre></div></div>
<p>This is worth knowing about, but for this series we will stick with the defaults plus <code>custom_folders</code>, which is the right level of customization for a typical analysis project.</p>
</section>
</section>
<section id="keep-the-defaults-that-support-the-long-game" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="keep-the-defaults-that-support-the-long-game"><span class="header-section-number">7</span> Keep the defaults that support the long game</h2>
<p>The full function signature exposes a few useful choices:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">init_project <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(path,</span>
<span id="cb10-2">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_renv      =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb10-3">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_git       =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb10-4">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">custom_folders =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-5">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">config        =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb10-6">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">open          =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb10-7">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">uw_branding   =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {}</span></code></pre></div></div>
<p>For this series, we want to keep the important defaults and add the folder we know we will need:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Do not run this yet.</span></span>
<span id="cb11-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This is the design we are choosing.</span></span>
<span id="cb11-3"></span>
<span id="cb11-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb11-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path           =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmer-penguins-analysis"</span>,</span>
<span id="cb11-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_renv       =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_git        =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">custom_folders =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/jobs"</span>,</span>
<span id="cb11-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">open           =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb11-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">uw_branding    =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb11-11">)</span></code></pre></div></div>
<p>The defaults are intentionally opinionated.</p>
<p><code>use_renv = TRUE</code> matters because package versions are part of the analysis. Later, <code>containr</code> will use the project’s <code>renv.lock</code> file to help build a container image. That image will make the project’s software environment portable.</p>
<p><code>use_git = TRUE</code> matters because the project will change as it moves through the series. Version control records those changes and gives you a history of the project: when the document was created, when the script changed, when the container was built, and when the submission workflow was added.</p>
<p><code>custom_folders = "data/jobs"</code> matters because high-throughput computing works best when a large task can be split into many independent pieces. We are not there yet, but the project structure is already making room for that step.</p>
<p><code>open = FALSE</code> is fine for this post because we are showing a scripted setup. In interactive work, you may prefer <code>open = TRUE</code> so the project opens after creation.</p>
<p><code>uw_branding = FALSE</code> keeps the scaffold generic. If you are creating a UW–Madison-facing project and want supported UW-branded assets, you can set it to <code>TRUE</code>.</p>
</section>
<section id="create-the-project" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="create-the-project"><span class="header-section-number">8</span> Create the project</h2>
<p>Now that we have made the design choices explicit, create the project.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(toolero)</span>
<span id="cb12-2"></span>
<span id="cb12-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">init_project</span>(</span>
<span id="cb12-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path           =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmer-penguins-analysis"</span>,</span>
<span id="cb12-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_renv       =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb12-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_git        =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb12-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">custom_folders =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/jobs"</span></span>
<span id="cb12-8">)</span></code></pre></div></div>
<p>After running this command, the project has a home and a folder structure that matches the workflow we are building toward.</p>
<p>A typical structure looks like this:</p>
<pre class="text"><code>palmer-penguins-analysis/
├── data/
│   └── jobs/
├── data-raw/
├── output/
│   ├── figures/
│   └── tables/
├── reports/
└── scripts/</code></pre>
<p>Depending on your local setup and options, you may also see files created by <code>renv</code>, <code>git</code>, or R project tooling.</p>
</section>
<section id="why-these-folders-matter" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="why-these-folders-matter"><span class="header-section-number">9</span> Why these folders matter</h2>
<p>The folder names are not magic. Their value comes from having a shared convention.</p>
<section id="data-raw" class="level3" data-number="9.1">
<h3 data-number="9.1" class="anchored" data-anchor-id="data-raw"><span class="header-section-number">9.1</span> <code>data-raw/</code></h3>
<p>Use <code>data-raw/</code> for original input data or files that are close to the original source. In this series, our starting dataset will live here:</p>
<pre class="text"><code>data-raw/palmer-penguins.csv</code></pre>
<p>That filename is specific on purpose. A name like <code>data.csv</code> is easy to type, but it becomes vague quickly. <code>palmer-penguins.csv</code> tells us what the file is before we open it.</p>
</section>
<section id="datajobs" class="level3" data-number="9.2">
<h3 data-number="9.2" class="anchored" data-anchor-id="datajobs"><span class="header-section-number">9.2</span> <code>data/jobs/</code></h3>
<p>Use <code>data/jobs/</code> for future job-sized inputs.</p>
<p>Later in the series, we will split the Palmer Penguins data into smaller files. Each file will be suitable for one independent job. That is the kind of structure CHTC can use well: many small, independent tasks instead of one large, monolithic run.</p>
<p>Creating <code>data/jobs/</code> now is a small way of keeping the long game visible.</p>
</section>
<section id="scripts" class="level3" data-number="9.3">
<h3 data-number="9.3" class="anchored" data-anchor-id="scripts"><span class="header-section-number">9.3</span> <code>scripts/</code></h3>
<p>Use <code>scripts/</code> for standalone scripts or helper programs. Early in a project, you may not need much here. As the project grows, this folder keeps executable code separate from one-off analysis documents.</p>
</section>
<section id="outputfigures-and-outputtables" class="level3" data-number="9.4">
<h3 data-number="9.4" class="anchored" data-anchor-id="outputfigures-and-outputtables"><span class="header-section-number">9.4</span> <code>output/figures/</code> and <code>output/tables/</code></h3>
<p>Use these folders for analysis outputs — plots, model results, CSV summaries, archived results from a cluster job. The point is to avoid mixing inputs and outputs. A future script should be able to read from known input locations and write to known output locations without depending on files scattered across the project.</p>
</section>
<section id="reports" class="level3" data-number="9.5">
<h3 data-number="9.5" class="anchored" data-anchor-id="reports"><span class="header-section-number">9.5</span> <code>reports/</code></h3>
<p>Use <code>reports/</code> for rendered documents, notes, or supporting documentation. In the next post, we will create a Quarto document that becomes the source of truth for the analysis. The important thing is that documentation is part of the project, not an afterthought stored somewhere else.</p>
</section>
</section>
<section id="put-the-dataset-where-it-belongs" class="level2" data-number="10">
<h2 data-number="10" class="anchored" data-anchor-id="put-the-dataset-where-it-belongs"><span class="header-section-number">10</span> Put the dataset where it belongs</h2>
<p>Now that the project exists, place the original dataset here:</p>
<pre class="text"><code>palmer-penguins-analysis/data-raw/palmer-penguins.csv</code></pre>
<p>This gives the original input file a clear home.</p>
<p>If you are creating the file from the <code>palmerpenguins</code> package, you could do that from inside the project:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install.packages("palmerpenguins")</span></span>
<span id="cb16-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install.packages("readr")</span></span>
<span id="cb16-3"></span>
<span id="cb16-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.exists</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw"</span>)) {</span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb16-6">}</span>
<span id="cb16-7"></span>
<span id="cb16-8">palmerpenguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb16-9">  readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw/palmer-penguins.csv"</span>)</span></code></pre></div></div>
<p>The important thing is not the mechanics of this particular dataset. The important thing is the habit: the original input file has a clear, stable, project-relative path.</p>
<p>That path will matter later. In Part 1, the Quarto document will read from <code>data-raw/palmer-penguins.csv</code>. In later parts, derived job inputs will be written under <code>data/jobs/</code>. Keeping those paths predictable makes the project easier to move from local analysis to command-line execution and eventually to CHTC.</p>
</section>
<section id="why-renv-matters-for-the-long-game" class="level2" data-number="11">
<h2 data-number="11" class="anchored" data-anchor-id="why-renv-matters-for-the-long-game"><span class="header-section-number">11</span> Why <code>renv</code> matters for the long game</h2>
<p>When <code>use_renv = TRUE</code>, <code>init_project()</code> initializes <code>renv</code> for the project. <code>renv</code> records the R packages used by the project in a lockfile called <code>renv.lock</code>.</p>
<p>That lockfile matters because package versions are part of the analysis. If a collaborator reruns the project with different package versions, the code may behave differently. If you return to the project months later, your library may no longer match the one you used originally.</p>
<p>For this series, <code>renv</code> also has a second role: it prepares the project for containerization.</p>
<p>In a later post, <code>containr</code> will use the project’s <code>renv.lock</code> file to help generate a container image. That image will capture the software environment needed to run the analysis somewhere other than your laptop.</p>
<p>So <code>renv</code> is not just a local reproducibility tool. It is part of the bridge from local work to portable execution.</p>
<p>A useful habit is:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">renv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package-name"</span>)</span>
<span id="cb17-2">renv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">snapshot</span>()</span></code></pre></div></div>
<p>Install packages through <code>renv</code>, then snapshot the project after changes to keep <code>renv.lock</code> current.</p>
</section>
<section id="why-git-matters-for-the-long-game" class="level2" data-number="12">
<h2 data-number="12" class="anchored" data-anchor-id="why-git-matters-for-the-long-game"><span class="header-section-number">12</span> Why <code>git</code> matters for the long game</h2>
<p>When <code>use_git = TRUE</code>, <code>init_project()</code> initializes version control with <code>git</code>.</p>
<p>Version control is not only for software developers. It is a research workflow tool. It records how the project changes over time and gives you a way to recover earlier states. It also makes collaboration safer because changes can be reviewed, compared, and merged deliberately.</p>
<p>For the Notebook-to-Cluster workflow, <code>git</code> gives you a project history that can answer practical questions later:</p>
<ul>
<li>When did the analysis script change?</li>
<li>Which version of the document produced these results?</li>
<li>What changed between the first local run and the cluster submission?</li>
<li>Which commit was used when the container image was built?</li>
</ul>
<p>Those questions are much easier to answer when version control starts at the beginning.</p>
</section>
<section id="what-we-have-after-part-0" class="level2" data-number="13">
<h2 data-number="13" class="anchored" data-anchor-id="what-we-have-after-part-0"><span class="header-section-number">13</span> What we have after Part 0</h2>
<p>At the end of Part 0, we have not analyzed anything yet. That is intentional.</p>
<p>What we have is a project that can grow:</p>
<pre class="text"><code>palmer-penguins-analysis/
├── data-raw/
│   └── palmer-penguins.csv
├── data/
│   └── jobs/
├── output/
│   ├── figures/
│   └── tables/
├── reports/
└── scripts/</code></pre>
<p>We also have the beginnings of two important records:</p>
<ul>
<li><code>renv.lock</code>, which records the package environment;</li>
<li>a <code>git</code> repository, which records the project history.</li>
</ul>
<p>This may feel like preparation rather than progress, but it is progress. A project with a stable home is easier to explain, easier to rerun, easier to containerize, and easier to submit to a computing system.</p>
</section>
<section id="what-comes-next" class="level2" data-number="14">
<h2 data-number="14" class="anchored" data-anchor-id="what-comes-next"><span class="header-section-number">14</span> What comes next</h2>
<p>In Part 1, we will create the document that carries the analysis.</p>
<p>That document will do more than hold code. It will become the source of truth for the workflow: prose, code, outputs, and decisions in one place. We will use <code>toolero::create_qmd()</code> to scaffold the Quarto document and automatically set up the post-render <code>purl()</code> step that derives a standalone <code>.R</code> script from the document.</p>
<p>That matters for the long game. The <code>.qmd</code> will be the human-readable notebook. The derived <code>.R</code> file will be the machine-executable script. Keeping those two connected is how we avoid code drift when the project moves from local exploration to command-line execution and eventually to CHTC.</p>
<p>For now, the project has a home.</p>
<p>That is the right first step.</p>


</section>

 ]]></description>
  <category>data-science</category>
  <category>R</category>
  <category>brug</category>
  <category>reproducibility</category>
  <category>research workflow</category>
  <category>project organization</category>
  <category>renv</category>
  <category>git</category>
  <category>CHTC</category>
  <category>portable code</category>
  <category>toolero</category>
  <guid>https://erwinlares.com/posts/2026-06-24-notebook-2-cluster-0-start-with-the-project/</guid>
  <pubDate>Wed, 24 Jun 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Add Alt-Text to your ggplot2 Plots</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-22-add-alt-text-to-your-ggplot2-plots/</link>
  <description><![CDATA[ 




<section id="a-small-step-to-make-content-more-accessible" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="a-small-step-to-make-content-more-accessible"><span class="header-section-number">1</span> A small step to make content more accessible</h2>
<p>UW–Madison digital accessibility policy states that “UW-Madison shall provide digital resources and information technology that are accessible to all, to the fullest extent technically feasible given an assessment of available resources, and subject to the Digital Accessibility Standards.”</p>
<p>Considering that the research artifacts researchers create and publish on the Data Science Platform end in <em>.wisc.edu</em>, we believe that they are subject to this policy and must be made accessible.</p>
<p>This post is the first of many to help researchers adopt with these accessibility requirements the easiest way possible. Today’s post covers adding alt-text to one’s ggplot2 generated plots and charts. Alt-text is a written description of an image that is read aloud by screen readers for people with visual impairments or those using assistive technologies. It also helps search engines understand the content of an image.</p>
</section>
<section id="a-toy-example" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="a-toy-example"><span class="header-section-number">2</span> A toy example</h2>
<p>The block of code below creates a plot using the dataset <em>mtcars</em> included with R. It plots the weight of the vehicles per 1000 pounds against the vehicle efficiency in miles per gallon. The resulting plots show that as the weight of the vehicle increases, the fuel efficiency decreases.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sample ggplot2 plot</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(mtcars, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> wt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> mpg)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Car Weight vs. Miles Per Gallon"</span>,</span>
<span id="cb1-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight (1000 lbs)"</span>,</span>
<span id="cb1-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Miles per Gallon"</span>,</span>
<span id="cb1-9">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alt =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A scatter plot showing vehicle fuel efficiency against vehicle weight"</span>,</span>
<span id="cb1-10">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Source: mtcars dataset"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-22-add-alt-text-to-your-ggplot2-plots/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>Plot with no alt-text property</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="ggplot2-limitations-and-an-html-work-around" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="ggplot2-limitations-and-an-html-work-around"><span class="header-section-number">3</span> ggplot2 limitations and an html work-around</h2>
<p>The very first thing one can do to make plots more accessible and easier to interpret is to clearly and succintly label all relevant parts of the plot. Minimally, these include providing a plot title and labeling the axes accordingly.</p>
<p>The <code>labs()</code> function from the <code>ggplot2()</code> package includes arguments such as <code>title</code>, <code>subtitle</code>, <code>caption</code>, <code>x</code>, and <code>y</code> that can help accomplish this minimal labeling to meet accessibility requirements</p>
<p>The <code>labs()</code> function also includes an <code>alt</code> argument. Unfortunately, at this time passing the alt-text as a value to the <code>alt</code> argument does not result in alt-text being available to screen readers. I am planning to submit an issue to the ggplot GitHub repo.</p>
<p>When this document is rendered to an html document the plot doesn’t result in a properly tagged plot with the intended alt-text attribute. Right-clicking on any element alows to <em>inspect</em> it. Doing so shows that the alt-text attribute is machine-generated alt-text and not accessible.</p>
<pre><code>&lt;img src="alt-text-ggplot-test_files/figure-html/unnamed-chunk-2-1.png" | 
class="img-fluid |
figure-img" width="672"&gt;</code></pre>
<p>Fortunately, there is an easy to implement solution. Next time a plot is needed, add the <code>fig-alt:</code> chunk option followed by the alt-text itself.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-22-add-alt-text-to-your-ggplot2-plots/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" alt="A scatter plot showing fuel efficiency against vehicle weight" width="672"></p>
<figcaption>Plot with alt-text property</figcaption>
</figure>
</div>
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>Where to place the code chunk options
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>Quarto gives the choice of placing chunk options as key:value pairs outside the curly brackets that identify the type of code chunk. Start with a <code>#|</code>, followed by the chunk option, a colon, and then the value.</p>
</div>
</div>
</div>
<p>With the <code>fig-alt</code> chunk option in place. The rendered plot bears the alt-text that makes the plot accessible. If we inspect the second plot, we see that the html element displaying the plot does, indeed, bear the appropriate alt-text attribute specified by the <code>fig-alt</code> chunk option.</p>
<pre><code>&lt;img src="alt-text-ggplot-test_files/figure-html/unnamed-chunk-3-1.png" |
class="img-fluid figure-img" |
alt="A scatter plot showing fuel efficiency against vehicle weight" 
width="672"&gt;</code></pre>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>Another useful fig- attribute
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>Adding <code>fig-cap</code> lets you caption your code chunk and makes it cross-referenceable across the document.</p>
</div>
</div>
</div>
</section>
<section id="tldr" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="tldr"><span class="header-section-number">4</span> tl;dr</h2>
<p>Include the code chunk option <code>fig-alt</code> in the code chunk that generates a plot to give the plot an alt-text attribute, like so:</p>
<pre><code>#| fig-alt: the alt-text goes here</code></pre>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-3-contents" aria-controls="callout-3" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>Read more about digital accessibility
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-3" class="callout-3-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p><a href="https://accessibility.huit.harvard.edu/describe-content-images">Harvard University Informational Technology</a> shares best practices when writing alt-text.</p>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>data-science</category>
  <category>r</category>
  <category>brug</category>
  <category>reproducibility</category>
  <category>accessibility</category>
  <guid>https://erwinlares.com/posts/2026-06-22-add-alt-text-to-your-ggplot2-plots/</guid>
  <pubDate>Mon, 22 Jun 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>less Maintenance, more Science</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-16-less-maintenance-more-science/</link>
  <description><![CDATA[ 




<hr>
<p>Reproducibility is, at its core, a commitment. A commitment to your future self, to those who will need to re-run the analysis six months from now when a reviewer asks a question you did not anticipate. A commitment to collaborators, who should be able to pick up where you left off. A commitment to the scientific record, which is only as trustworthy as the code behind it.</p>
<p>That commitment rests on a quiet assumption: that the code remains stable across time and across contexts. It is worth pausing on that word, <em>contexts</em>, because it is where most reproducibility problems actually enter – not in a single dramatic failure, but incrementally, through a process I have started thinking of as <em>code drift</em>.</p>
<section id="the-drift-problem" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="the-drift-problem"><span class="header-section-number">1</span> The Drift Problem</h2>
<p>Here is how it usually goes. You write an analysis interactively in RStudio, reading your data from <code>data-raw/penguins.csv</code>. It works. A few weeks later, you fold that analysis into a Quarto document. The path breaks – <code>knitr</code> uses the document directory as the working directory, not the project root – so you patch it. Then you want to run the same logic as a standalone script, maybe to test it before submitting it to a computing cluster. The path breaks again, differently, and you patch it again.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-16-less-maintenance-more-science/less-maintenance-more-science.png" class="img-fluid figure-img"></p>
<figcaption>One source of truth prevents code drift and produces consistent, reproducible artifacts.</figcaption>
</figure>
</div>
<p>You now have three versions of the same input line:</p>
<pre><code># Works interactively
data &lt;- read_clean_csv("data-raw/penguins.csv")

# Patched for Quarto
data &lt;- read_clean_csv("../data-raw/penguins.csv")

# Patched again for Rscript / cluster submission
data &lt;- read_clean_csv(commandArgs(trailingOnly = TRUE)[1])</code></pre>
<p>None of these lines is wrong in isolation. The problem is that they now live in different versions of the same analysis. This is code drift. It is not a dramatic failure – no error is thrown, no alarm sounds – it is the slow divergence between what you report and what you actually ran. The danger is that it is invisible until it isn’t.</p>
</section>
<section id="three-contexts-three-conventions" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="three-contexts-three-conventions"><span class="header-section-number">2</span> Three Contexts, Three Conventions</h2>
<p>To be concrete about what we are dealing with, it helps to name the three contexts a research workflow typically passes through.</p>
<p><strong>Interactive.</strong> You are working in RStudio or another IDE. The working directory is set by the <code>.Rproj</code> file, typically the project root. Parameters are set by hand or read from a config file. This is where most analyses are written.</p>
<p><strong>Quarto.</strong> Your code lives inside a <code>.qmd</code> document. When <code>quarto render</code> is called, <code>knitr</code> uses the document’s directory as the working directory – which may or may not be the project root, depending on where the document lives. Parameters arrive via the <code>params</code> key in the YAML header.</p>
<p><strong>Rscript / HTCondor.</strong> The code runs as a standalone script, dispatched by a job scheduler or launched from the command line. The working directory is wherever the script is called from. Parameters arrive via <code>commandArgs(trailingOnly = TRUE)</code>.</p>
<p>None of these contexts share a common convention for how inputs are located or how parameters arrive. The typical response is to manage this informally: separate scripts for each context, lines commented in and out depending on how you plan to run the code, a note to yourself that says “remember to update the path before submitting.” These are reasonable workarounds. They are also precisely where drift lives. Each individual fix feels local and harmless. That is exactly why they accumulate.</p>
</section>
<section id="one-maintained-source-two-derived-artifacts" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="one-maintained-source-two-derived-artifacts"><span class="header-section-number">3</span> One Maintained Source, Two Derived Artifacts</h2>
<p>There is a more principled alternative, and it starts with a shift in how you think about the Quarto document.</p>
<p>The conventional view is that a .qmd file is a report — a narrative wrapper around the analysis code, useful for communication. The view I want to argue for here is older than Quarto: it is the core claim of literate programming, that code and the reasoning behind it belong together in the same document. What I am adding to that idea is a practical consequence — the .qmd can also serve as a source, the canonical maintained version of the analysis from which everything else is derived.</p>
<p>The rendered HTML or PDF is one derived artifact. The standalone .R script for cluster submission is another. Neither is maintained directly; both are produced from the same source. And because the reasoning lives alongside the code, returning to the analysis — or handing it to someone else — does not require reconstructing decisions that were made under pressure and never written down.</p>
<p>If the report and the script are both derived from the same .qmd, they cannot drift. That is reproducibility by design: divergence is structurally difficult rather than merely inadvisable.</p>
</section>
<section id="scaffolding-the-source-with-create_qmd" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="scaffolding-the-source-with-create_qmd"><span class="header-section-number">4</span> Scaffolding the Source with <code>create_qmd()</code></h2>
<p>The first function is <code>create_qmd()</code>. It scaffolds a new Quarto document from a template that is oriented from the start toward portability – toward being a maintained source rather than a one-off report.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(toolero)</span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_qmd</span>(</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path      =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"analysis.qmd"</span>,</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yaml_data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author.yml"</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pre-populates author metadata; see note below</span></span>
<span id="cb2-7">)</span></code></pre></div></div>
</div>
<p>A note on <code>yaml_data</code>: the argument accepts a path to a YAML file containing metadata – author name, affiliation, ORCID, email – that gets merged into the document’s YAML header at scaffold time. It is a small quality-of-life detail, but it removes one more reason to postpone setting things up correctly. Your name is already in the document before you write a line of analysis. A minimal <code>author.yml</code> might look like this:</p>
<pre><code>author:
  - name: "Erwin Lares"
    affiliation: "University of Wisconsin-Madison"
    orcid: "0000-0002-3284-828X"
    email: "erwin.lares@wisc.edu"</code></pre>
<p><code>create_qmd()</code> produces this:</p>
<pre><code>analysis.qmd       # the maintained source document
data-raw/          # sample dataset (Palmer Penguins subset)
assets/            # placeholder logo
_quarto.yml        # project config, registers the post-render hook
R/purl.R           # helper script called by the hook
R/analysis.R       # derived script, produced on first render</code></pre>
<p>The key thing the template encodes – beyond structure and YAML – is a dedicated input resolution chunk that loads <code>toolero</code> and calls <code>detect_execution_context()</code>. It appears in the document before the data-loading section, and it is already wired to <code>params$input_file</code> for the Quarto context. You do not have to add it manually. It is there, waiting for the analysis to be written around it. That design choice is the subject of the next section.</p>
<p>One note: this full setup – the worked example, the sample data, and the context-detection chunk – is what you get with the default <code>include_examples = TRUE</code>. If you call <code>create_qmd()</code> with <code>include_examples = FALSE</code>, you get a minimal skeleton with a setup chunk that loads <code>toolero</code>, but without the input resolution block. For a new analysis intended to run across all three contexts, the default is what you want.</p>
</section>
<section id="context-awareness-at-the-point-of-input" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="context-awareness-at-the-point-of-input"><span class="header-section-number">5</span> Context Awareness at the Point of Input</h2>
<p>R code does not know, by default, how it is being run. This sounds like a minor limitation until you try to write code that behaves correctly in all three contexts. The naive solution is <code>if (interactive())</code> – check whether the session is interactive, branch on that. This almost works, and almost is the problem: <code>interactive()</code> returns <code>FALSE</code> during <code>quarto render</code>, so the check cannot distinguish a Quarto render from an <code>Rscript</code> call. Most people reach for <code>interactive()</code> first. Most people get it wrong.</p>
<p><code>detect_execution_context()</code> solves this correctly. It returns one of three strings – <code>"interactive"</code>, <code>"quarto"</code>, or <code>"rscript"</code> – and that single value is enough to drive a <code>switch</code> block that resolves inputs correctly for each context:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">context <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detect_execution_context</span>()</span>
<span id="cb5-2"></span>
<span id="cb5-3">input_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">switch</span>(context,</span>
<span id="cb5-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interactive =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data-raw/penguins.csv"</span>,</span>
<span id="cb5-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quarto      =</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>input_file,</span>
<span id="cb5-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rscript     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">commandArgs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trailingOnly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb5-7">)</span>
<span id="cb5-8"></span>
<span id="cb5-9">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_clean_csv</span>(input_file)</span></code></pre></div></div>
</div>
<p>This replaces the three diverging versions from the opening section with one. The branching is explicit and readable: anyone who opens the file can see immediately that it was written to run in three contexts and understand what each one does. Recall the informal workarounds we named earlier – separate scripts, commented-out lines. This is the structured alternative. The intent is visible in the code rather than in a comment or a memory.</p>
<p>The phrase I keep coming back to is <em>portable in fact rather than just in theory</em>. Context detection is the piece that closes that gap. Without it, extracting the script for cluster use still requires manual adaptation. With it, the extracted script is already correct.</p>
<p>Because <code>create_qmd()</code> includes this block in the template by default, an author using the scaffold does not have to add it. It is there from the first render.</p>
</section>
<section id="closing-the-loop-the-post-render-hook" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="closing-the-loop-the-post-render-hook"><span class="header-section-number">6</span> Closing the Loop: The Post-Render Hook</h2>
<p>The final piece is the mechanism that turns the maintained <code>.qmd</code> into a derived <code>.R</code> script automatically. When <code>create_qmd()</code> scaffolds the project, it writes a <code>_quarto.yml</code> that registers a post-render hook:</p>
<pre><code>project:
  post-render: Rscript R/purl.R</code></pre>
<p>And <code>R/purl.R</code>, which that hook calls, does this:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">qmd_files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir_ls</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getwd</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">glob =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*.qmd"</span>)</span>
<span id="cb7-2"></span>
<span id="cb7-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (input <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> qmd_files) {</span>
<span id="cb7-4">  output <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, fs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path_ext_set</span>(fs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path_file</span>(input), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>))</span>
<span id="cb7-5">  knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">purl</span>(input, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output =</span> output, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">documentation =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb7-6">}</span></code></pre></div></div>
</div>
<p>It scans the project root for <code>.qmd</code> files and writes a corresponding <code>.R</code> file into <code>R/</code>. So <code>analysis.qmd</code> becomes <code>R/analysis.R</code>. Because the target document is resolved dynamically rather than hardcoded, the same <code>purl.R</code> works regardless of what you named your document.</p>
<p>It is worth being clear that <code>knitr::purl()</code> is not a <code>toolero</code> function – it is from <code>knitr</code>, and it has existed for years. What <code>create_qmd()</code> contributes is that the hook is already registered and the project is already structured so that the extraction makes sense. The author does not have to remember to run <code>purl()</code> after editing the document. Render, and the script appears.</p>
<p>There is a manual counterpart, <code>toolero::qmd_to_r()</code>, for cases where you want to extract a script from an existing document without going through the full render cycle. The hook and <code>qmd_to_r()</code> are doing the same basic thing; the hook just does it automatically.</p>
<p>Because <code>detect_execution_context()</code> is baked into the document from the start, the extracted script inherits context-aware input resolution without any additional work. It is ready to be wrapped by a submission workflow – a HTCondor submit file, a Slurm batch script, whatever the cluster requires – without editing the analysis logic itself. The remaining cluster work is submission mechanics, not debugging code that was written for a different context.</p>
</section>
<section id="from-source-to-submission" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="from-source-to-submission"><span class="header-section-number">7</span> From Source to Submission</h2>
<p>The full workflow is a short sequence:</p>
<ol type="1">
<li><strong>Scaffold</strong> with <code>create_qmd()</code> – author metadata in place, context detection wired, post-render hook registered.</li>
<li><strong>Write</strong> the analysis once, inside the <code>.qmd</code>.</li>
<li><strong>Render</strong> – which produces the report and emits the <code>.R</code> script as a side effect.</li>
<li><strong>Submit</strong> the script to HTCondor or any other job scheduler, wrapped by the appropriate submission infrastructure.</li>
</ol>
<p>One maintained source. Two derived artifacts. No manual synchronization. The workflow does not ask you to be disciplined about keeping the report and the script in sync – it removes the step where they would otherwise diverge.</p>
<p>This is also worth saying plainly: this approach earns its keep most at the <em>beginning</em> of a project, before the workarounds accumulate. Retrofitting an existing analysis into this structure is possible, but you are undoing decisions that were made under pressure. The earlier the scaffold is in place, the less there is to undo.</p>
</section>
<section id="what-this-does-and-does-not-solve" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="what-this-does-and-does-not-solve"><span class="header-section-number">8</span> What This Does and Does Not Solve</h2>
<p>I want to be honest about the limits here.</p>
<p>Context detection handles input resolution. It does not handle the R environment itself. If your interactive session and the cluster node are running different versions of a package – or different versions of R – the analysis may not reproduce even with identical code. That is a container problem, not a context problem. It is the next layer in the stack, and it is what the <a href="https://github.com/erwinlares/containr"><code>containr</code></a> package is designed to address: building and pushing a reproducible execution environment alongside the analysis.</p>
<p>The <code>purl()</code> approach extracts all R code chunks from the document. That means chunk tagging strategy matters. Chunks that exist purely for the rendered report – formatting a display table, generating a figure with custom theming – should be tagged with <code>purl = FALSE</code> to keep the extracted script clean and focused on computation.</p>
<p>Finally, this workflow assumes the document and the submission script are doing the same computational work. If the cluster job is a scaled-up version of a local prototype – more data, more iterations, different resource requirements – some intentional adaptation is still necessary. The goal is to eliminate <em>accidental</em> divergence, not to prohibit <em>deliberate</em> differences. Those are different problems, and conflating them would overclaim what any scaffolding tool can do.</p>
<hr>
</section>
<section id="summary" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="summary"><span class="header-section-number">9</span> Summary</h2>
<p>Code drift is a reproducibility problem, and it is a quiet one. It does not announce itself. It accumulates through small, individually reasonable decisions – patched paths, context-specific parameters, separate entry points – until the code you submitted to the cluster is no longer quite the code in your report.</p>
<p><code>toolero</code> addresses this structurally, through three pieces that work together: <code>create_qmd()</code> scaffolds a document designed to be a maintained source; <code>detect_execution_context()</code> makes input resolution explicit and correct across all three execution contexts; and the post-render <code>knitr::purl()</code> hook derives the cluster script from the document automatically. The result is a workflow where divergence is difficult by design rather than inadvisable by convention.</p>
<p>The functions are small. The commitment they encode is not.</p>
<hr>
<p><em><code>toolero</code> is available on CRAN. Install with <code>install.packages("toolero")</code>.</em> <em>Source and issues: <a href="https://github.com/erwinlares/toolero">https://github.com/erwinlares/toolero</a></em></p>


</section>

 ]]></description>
  <category>r</category>
  <category>reproducibility</category>
  <category>coding</category>
  <guid>https://erwinlares.com/posts/2026-06-16-less-maintenance-more-science/</guid>
  <pubDate>Tue, 16 Jun 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Git Push Origin Me</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-05-git-push-origin-me/</link>
  <description><![CDATA[ 




<p>My personal website has been quietly embarrassing me since 2021. Not in a dramatic way — it was still up, still rendering — but frozen in time in a way that felt increasingly dishonest. The version of me it described was a dissertator with a vague set of interests and a handful of blog posts from a pandemic year. I’ve since graduated, changed roles, became a hobby potter, and taken on a fair number of other things the old site didn’t know about.</p>
<p>The deeper problem is that I am, professionally and creatively, several people at once. I work as a research Data Science consultant for the University of Wisconsin-Madison, main a website to showcase my pottery, maintain a second website for the aikido studio, and a GitHub Pages site for the R community I’m starting in the fall. None of these talk to each other. If I write something at the intersection of pottery and data science — which happens more than you’d think — I have no clean way to surface it in both places. Every post either lives on one platform or gets manually duplicated, which means it usually doesn’t get written at all.</p>
<p>The need was clear: a unified personal site that serves as the canonical source of truth for everything I write, with a way to route content outward to the right platforms automatically.</p>
<p>The hurdles were predictable. The old site ran on Hugo, which I had stopped understanding some time ago. The Netlify project existed but was disconnected from its GitHub repo — apparently I unlinked them at some point and forgot. The platforms I write for speak different languages: some take Git pushes, some have REST APIs, one has a Content API that may or may not be accessible on my plan. Getting all of this to play nicely with a single source file was going to take some design work before any coding.</p>
<p>The solution I landed on is a hub-and-spoke model. This site is the hub, built in Quarto and deployed via Netlify from a GitHub repository. Every post lives here as a single .qmd file with a YAML header that carries routing metadata: which platforms it should go to, and whether it’s ready to publish. A small R script reads that metadata and handles dispatch — a git push for static sites, authenticated API calls for the others.</p>
<p>The dispatch layer is still being built. But the hub is up, the pipeline is running, and the first posts are in. It’s a start.</p>



 ]]></description>
  <category>journal</category>
  <category>productivity</category>
  <category>coding</category>
  <guid>https://erwinlares.com/posts/2026-06-05-git-push-origin-me/</guid>
  <pubDate>Fri, 05 Jun 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Split, Apply, Combine</title>
  <dc:creator>Erwin Lares</dc:creator>
  <link>https://erwinlares.com/posts/2026-06-05-split-apply-combine/</link>
  <description><![CDATA[ 




<section id="the-problem-one-analysis-multiple-datasets" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="the-problem-one-analysis-multiple-datasets"><span class="header-section-number">1</span> The problem: one analysis, multiple datasets</h2>
<p>Many research workflows require the same analysis to be repeated across subsets of a larger dataset. We may want to summarize measurements within subsets defined by species, treatment group, geography, or any other grouping variable. In this post, I use the Palmer Penguins dataset to walk through several ways to express this split-apply-combine pattern: split the data into groups, apply the same analysis to each group, and combine the results into a single output.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://erwinlares.com/posts/2026-06-05-split-apply-combine/split-apply-combine-diagram.png" class="img-fluid figure-img"></p>
<figcaption>Split-apply-combine workflow</figcaption>
</figure>
</div>
<p>The examples start with deliberately explicit code, then move through progressively more abstract approaches: for loops, <code>across()</code>, <code>group_modify()</code>, <code>map()</code>, and finally <code>future_map()</code>. Each approach solves the same basic problem, but each emphasizes a different way of thinking about repeated work. The goal is not to argue that every approach is equally appropriate for this particular summary table. Instead, the goal is to show how the same analysis can be reorganized as the workflow becomes more complex, more reusable, or better suited to parallel execution.</p>
<p>The last part of the post explores how to take advantage of the multiple cores available on modern computers. Parallel execution is not always faster, especially for small examples, but the programming pattern is useful when the same analysis must be repeated across many files, groups, simulations, or model-fitting tasks.</p>
</section>
<section id="input-resolution" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="input-resolution"><span class="header-section-number">2</span> Input resolution</h2>
<p>This function — from toolero, a package developed at RCI for managing execution context across environments — allows one codebase to resolve input files differently depending on how the code is being run. That is useful for avoiding code drift between interactive development, report rendering, and command-line execution.</p>
<p>The logic is straightforward. When you call <code>detect_execution_context()</code>, it returns one of three values: <code>interactive</code>, <code>quarto</code>, or <code>rscript</code>. Knowing the execution context lets the script decide where the input path should come from. In interactive mode, the path can be hardcoded for local development. During Quarto rendering, the path can come from a document parameter. When the code runs from the command line with <code>Rscript</code>, the path can come from a positional command-line argument.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># detect_execution_context() identifies which of three environments this</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># code is running in: interactive RStudio, quarto render, or Rscript.</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Each context resolves the input file path differently.</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   interactive : you are running chunks in RStudio -- path is hardcoded</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                 to the local data file for development convenience</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   quarto      : document is being rendered -- path comes from params</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                 defined in the YAML header above</span></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   rscript     : document is running on a remote cluster -- path comes</span></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#                 from the first command line argument</span></span>
<span id="cb1-11"></span>
<span id="cb1-12">context <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detect_execution_context</span>()</span>
<span id="cb1-13"></span>
<span id="cb1-14">input_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">switch</span>(context,</span>
<span id="cb1-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interactive =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"palmerpenguins.csv"</span>,</span>
<span id="cb1-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quarto      =</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>input_file,</span>
<span id="cb1-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rscript     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">commandArgs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trailingOnly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb1-18">)</span>
<span id="cb1-19"></span>
<span id="cb1-20">penguins <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(input_file)</span></code></pre></div></div>
</details>
</div>
</section>
<section id="tabular-results-per-species" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="tabular-results-per-species"><span class="header-section-number">3</span> Tabular results per species</h2>
<p>I do not want the analysis itself to distract from the process I want to showcase. For this post, I limit the analysis to a set of descriptive statistics applied to the Palmer Penguins dataset. In short, we want to understand how several body measurements are distributed across species. This gives us a compact example that is simple enough to follow, but rich enough to demonstrate several ways of applying the same analysis to multiple subsets.</p>
<p>The summary statistics include measures of central tendency, range, spread, and selected quantiles for four measurement variables: body mass, flipper length, bill length, and bill depth.</p>
</section>
<section id="approach-1-explicit-summaries" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="approach-1-explicit-summaries"><span class="header-section-number">4</span> Approach 1: Explicit summaries</h2>
<p>The first approach writes every calculation separately. This is a deliberately explicit implementation. It is readable in the sense that every output column is spelled out, but it is also verbose, repetitive, easy to mistype, and difficult to maintain as the number of variables or summary functions grows.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Explicit code"</span>)</span>
<span id="cb2-2"></span>
<span id="cb2-3">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb2-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n            =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb2-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(body_mass_g),</span>
<span id="cb2-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(flipper_length_mm),</span>
<span id="cb2-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(bill_length_mm),</span>
<span id="cb2-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(bill_depth_mm),</span>
<span id="cb2-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_mass_25    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(body_mass_g, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_flipper_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(flipper_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_length_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bill_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_depth_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bill_depth_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_mass_75    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(body_mass_g, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_flipper_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(flipper_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_length_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bill_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_depth_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bill_depth_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb2-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_mass    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-41">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb2-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-43">  )</span>
<span id="cb2-44"></span>
<span id="cb2-45">end_time <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Explicit code: 0.009 sec elapsed</code></pre>
</div>
</div>
<p>The resulting tibble is wide, so the rendered table shows only part of the output at a time.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb4-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb4-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb4-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb4-7">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="oytooerfkv" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#oytooerfkv table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#oytooerfkv thead, #oytooerfkv tbody, #oytooerfkv tfoot, #oytooerfkv tr, #oytooerfkv td, #oytooerfkv th {
  border-style: none;
}

#oytooerfkv p {
  margin: 0;
  padding: 0;
}

#oytooerfkv .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#oytooerfkv .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#oytooerfkv .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#oytooerfkv .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#oytooerfkv .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#oytooerfkv .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#oytooerfkv .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#oytooerfkv .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#oytooerfkv .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#oytooerfkv .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#oytooerfkv .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#oytooerfkv .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#oytooerfkv .gt_spanner_row {
  border-bottom-style: hidden;
}

#oytooerfkv .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#oytooerfkv .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#oytooerfkv .gt_from_md > :first-child {
  margin-top: 0;
}

#oytooerfkv .gt_from_md > :last-child {
  margin-bottom: 0;
}

#oytooerfkv .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#oytooerfkv .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#oytooerfkv .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#oytooerfkv .gt_row_group_first td {
  border-top-width: 2px;
}

#oytooerfkv .gt_row_group_first th {
  border-top-width: 2px;
}

#oytooerfkv .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#oytooerfkv .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#oytooerfkv .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#oytooerfkv .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#oytooerfkv .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#oytooerfkv .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#oytooerfkv .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#oytooerfkv .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#oytooerfkv .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#oytooerfkv .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#oytooerfkv .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#oytooerfkv .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#oytooerfkv .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#oytooerfkv .gt_left {
  text-align: left;
}

#oytooerfkv .gt_center {
  text-align: center;
}

#oytooerfkv .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#oytooerfkv .gt_font_normal {
  font-weight: normal;
}

#oytooerfkv .gt_font_bold {
  font-weight: bold;
}

#oytooerfkv .gt_font_italic {
  font-style: italic;
}

#oytooerfkv .gt_super {
  font-size: 65%;
}

#oytooerfkv .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#oytooerfkv .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#oytooerfkv .gt_indent_1 {
  text-indent: 5px;
}

#oytooerfkv .gt_indent_2 {
  text-indent: 10px;
}

#oytooerfkv .gt_indent_3 {
  text-indent: 15px;
}

#oytooerfkv .gt_indent_4 {
  text-indent: 20px;
}

#oytooerfkv .gt_indent_5 {
  text-indent: 25px;
}

#oytooerfkv .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#oytooerfkv div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_mass</th>
<th id="mean_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper</th>
<th id="mean_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length</th>
<th id="mean_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth</th>
<th id="min_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_mass</th>
<th id="min_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper</th>
<th id="min_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length</th>
<th id="min_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth</th>
<th id="max_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_mass</th>
<th id="max_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper</th>
<th id="max_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length</th>
<th id="max_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth</th>
<th id="sd_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_mass</th>
<th id="sd_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper</th>
<th id="sd_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length</th>
<th id="sd_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth</th>
<th id="var_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_mass</th>
<th id="var_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper</th>
<th id="var_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length</th>
<th id="var_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth</th>
<th id="length_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_mass</th>
<th id="length_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper</th>
<th id="length_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length</th>
<th id="length_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth</th>
<th id="quantile_mass_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_mass_25</th>
<th id="quantile_flipper_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_flipper_25</th>
<th id="quantile_bill_length_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_length_25</th>
<th id="quantile_bill_depth_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_depth_25</th>
<th id="quantile_mass_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_mass_75</th>
<th id="quantile_flipper_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_flipper_75</th>
<th id="quantile_bill_length_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_length_75</th>
<th id="quantile_bill_depth_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_depth_75</th>
<th id="iqr_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_mass</th>
<th id="iqr_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper</th>
<th id="iqr_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length</th>
<th id="iqr_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,700.66</td>
<td class="gt_row gt_right" headers="mean_flipper">189.95</td>
<td class="gt_row gt_right" headers="mean_bill_length">38.79</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.35</td>
<td class="gt_row gt_right" headers="min_mass">2,850.00</td>
<td class="gt_row gt_right" headers="min_flipper">172.00</td>
<td class="gt_row gt_right" headers="min_bill_length">32.10</td>
<td class="gt_row gt_right" headers="min_bill_depth">15.50</td>
<td class="gt_row gt_right" headers="max_mass">4,775.00</td>
<td class="gt_row gt_right" headers="max_flipper">210.00</td>
<td class="gt_row gt_right" headers="max_bill_length">46.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">21.50</td>
<td class="gt_row gt_right" headers="sd_mass">458.57</td>
<td class="gt_row gt_right" headers="sd_flipper">6.54</td>
<td class="gt_row gt_right" headers="sd_bill_length">2.66</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.22</td>
<td class="gt_row gt_right" headers="var_mass">210,282.89</td>
<td class="gt_row gt_right" headers="var_flipper">42.76</td>
<td class="gt_row gt_right" headers="var_bill_length">7.09</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.48</td>
<td class="gt_row gt_right" headers="length_mass">152.00</td>
<td class="gt_row gt_right" headers="length_flipper">152.00</td>
<td class="gt_row gt_right" headers="length_bill_length">152.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">152.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">3,350.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">186.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">36.75</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">17.50</td>
<td class="gt_row gt_right" headers="quantile_mass_75">4,000.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">195.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">40.75</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">19.00</td>
<td class="gt_row gt_right" headers="iqr_mass">650.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,733.09</td>
<td class="gt_row gt_right" headers="mean_flipper">195.82</td>
<td class="gt_row gt_right" headers="mean_bill_length">48.83</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.42</td>
<td class="gt_row gt_right" headers="min_mass">2,700.00</td>
<td class="gt_row gt_right" headers="min_flipper">178.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">16.40</td>
<td class="gt_row gt_right" headers="max_mass">4,800.00</td>
<td class="gt_row gt_right" headers="max_flipper">212.00</td>
<td class="gt_row gt_right" headers="max_bill_length">58.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">20.80</td>
<td class="gt_row gt_right" headers="sd_mass">384.34</td>
<td class="gt_row gt_right" headers="sd_flipper">7.13</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.34</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.14</td>
<td class="gt_row gt_right" headers="var_mass">147,713.45</td>
<td class="gt_row gt_right" headers="var_flipper">50.86</td>
<td class="gt_row gt_right" headers="var_bill_length">11.15</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.29</td>
<td class="gt_row gt_right" headers="length_mass">68.00</td>
<td class="gt_row gt_right" headers="length_flipper">68.00</td>
<td class="gt_row gt_right" headers="length_bill_length">68.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">68.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">3,487.50</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">191.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">46.35</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">17.50</td>
<td class="gt_row gt_right" headers="quantile_mass_75">3,950.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">201.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">51.08</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">19.40</td>
<td class="gt_row gt_right" headers="iqr_mass">462.50</td>
<td class="gt_row gt_right" headers="iqr_flipper">10.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.73</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.90</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_mass">5,076.02</td>
<td class="gt_row gt_right" headers="mean_flipper">217.19</td>
<td class="gt_row gt_right" headers="mean_bill_length">47.50</td>
<td class="gt_row gt_right" headers="mean_bill_depth">14.98</td>
<td class="gt_row gt_right" headers="min_mass">3,950.00</td>
<td class="gt_row gt_right" headers="min_flipper">203.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">13.10</td>
<td class="gt_row gt_right" headers="max_mass">6,300.00</td>
<td class="gt_row gt_right" headers="max_flipper">231.00</td>
<td class="gt_row gt_right" headers="max_bill_length">59.60</td>
<td class="gt_row gt_right" headers="max_bill_depth">17.30</td>
<td class="gt_row gt_right" headers="sd_mass">504.12</td>
<td class="gt_row gt_right" headers="sd_flipper">6.48</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.08</td>
<td class="gt_row gt_right" headers="sd_bill_depth">0.98</td>
<td class="gt_row gt_right" headers="var_mass">254,133.18</td>
<td class="gt_row gt_right" headers="var_flipper">42.05</td>
<td class="gt_row gt_right" headers="var_bill_length">9.50</td>
<td class="gt_row gt_right" headers="var_bill_depth">0.96</td>
<td class="gt_row gt_right" headers="length_mass">124.00</td>
<td class="gt_row gt_right" headers="length_flipper">124.00</td>
<td class="gt_row gt_right" headers="length_bill_length">124.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">124.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">4,700.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">212.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">45.30</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">14.20</td>
<td class="gt_row gt_right" headers="quantile_mass_75">5,500.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">221.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">49.55</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">15.70</td>
<td class="gt_row gt_right" headers="iqr_mass">800.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.25</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>The word “explicit” should not be read as a criticism. Explicit code has real value — it is maximally transparent, and in a teaching context that transparency is the point. The weakness is that explicit code does not scale well. Once you add more variables or more summary functions, the code becomes harder to maintain and easier to break.</p>
<p>On my 2024 MacBook Pro, for the extended Penguin dataset consisting of 344 rows and 8 columns, the explicit approach took approximately 2.019 seconds to run.</p>
</section>
<section id="approach-2-for-loops" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="approach-2-for-loops"><span class="header-section-number">5</span> Approach 2: For loops</h2>
<p>For loops make the repeated structure of the task visible. Rather than asking <code>dplyr</code> to perform the repetition for us, we can write the repetition ourselves. This is not necessarily the most concise or idiomatic way to solve the problem in R, but it is useful for understanding what grouped summaries are doing: they repeat the same operation over smaller pieces of a larger dataset.</p>
<section id="approach-2.1-looping-over-species" class="level3" data-number="5.1">
<h3 data-number="5.1" class="anchored" data-anchor-id="approach-2.1-looping-over-species"><span class="header-section-number">5.1</span> Approach 2.1: Looping over species</h3>
<p>A loop over species makes the grouping logic explicit. For each species, we filter the data, compute one row of summaries, store that row in a list, and then bind the results together.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"for loop for species"</span>)</span>
<span id="cb5-2"></span>
<span id="cb5-3">species_values <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(penguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>species)</span>
<span id="cb5-4"></span>
<span id="cb5-5">results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(species_values))</span>
<span id="cb5-6"></span>
<span id="cb5-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(species_values)) {</span>
<span id="cb5-8">  species_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> species_values[[i]]</span>
<span id="cb5-9"></span>
<span id="cb5-10">  data_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(species <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> species_i)</span>
<span id="cb5-12"></span>
<span id="cb5-13">  results[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb5-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> species_i,</span>
<span id="cb5-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(data_i),</span>
<span id="cb5-16"></span>
<span id="cb5-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-21"></span>
<span id="cb5-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-26"></span>
<span id="cb5-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-31"></span>
<span id="cb5-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-36"></span>
<span id="cb5-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-41"></span>
<span id="cb5-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g),</span>
<span id="cb5-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm),</span>
<span id="cb5-44">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm),</span>
<span id="cb5-45">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm),</span>
<span id="cb5-46"></span>
<span id="cb5-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_mass_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_flipper_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-49">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_length_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-50">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_depth_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-51"></span>
<span id="cb5-52">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_mass_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-53">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_flipper_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-54">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_length_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-55">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile_bill_depth_75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb5-56"></span>
<span id="cb5-57">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_mass =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>body_mass_g, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_flipper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>flipper_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-59">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_bill_length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_length_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb5-60">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr_bill_depth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(data_i<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bill_depth_mm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb5-61">  )</span>
<span id="cb5-62">}</span>
<span id="cb5-63"></span>
<span id="cb5-64">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(results)</span>
<span id="cb5-65"></span>
<span id="cb5-66">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb5-69">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb5-70">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb5-71">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb5-72">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fwyttoiycd" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#fwyttoiycd table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#fwyttoiycd thead, #fwyttoiycd tbody, #fwyttoiycd tfoot, #fwyttoiycd tr, #fwyttoiycd td, #fwyttoiycd th {
  border-style: none;
}

#fwyttoiycd p {
  margin: 0;
  padding: 0;
}

#fwyttoiycd .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#fwyttoiycd .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#fwyttoiycd .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#fwyttoiycd .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#fwyttoiycd .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#fwyttoiycd .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fwyttoiycd .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#fwyttoiycd .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#fwyttoiycd .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#fwyttoiycd .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#fwyttoiycd .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#fwyttoiycd .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#fwyttoiycd .gt_spanner_row {
  border-bottom-style: hidden;
}

#fwyttoiycd .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#fwyttoiycd .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#fwyttoiycd .gt_from_md > :first-child {
  margin-top: 0;
}

#fwyttoiycd .gt_from_md > :last-child {
  margin-bottom: 0;
}

#fwyttoiycd .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#fwyttoiycd .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#fwyttoiycd .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#fwyttoiycd .gt_row_group_first td {
  border-top-width: 2px;
}

#fwyttoiycd .gt_row_group_first th {
  border-top-width: 2px;
}

#fwyttoiycd .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#fwyttoiycd .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#fwyttoiycd .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#fwyttoiycd .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fwyttoiycd .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#fwyttoiycd .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#fwyttoiycd .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#fwyttoiycd .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#fwyttoiycd .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fwyttoiycd .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#fwyttoiycd .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#fwyttoiycd .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#fwyttoiycd .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#fwyttoiycd .gt_left {
  text-align: left;
}

#fwyttoiycd .gt_center {
  text-align: center;
}

#fwyttoiycd .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#fwyttoiycd .gt_font_normal {
  font-weight: normal;
}

#fwyttoiycd .gt_font_bold {
  font-weight: bold;
}

#fwyttoiycd .gt_font_italic {
  font-style: italic;
}

#fwyttoiycd .gt_super {
  font-size: 65%;
}

#fwyttoiycd .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#fwyttoiycd .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#fwyttoiycd .gt_indent_1 {
  text-indent: 5px;
}

#fwyttoiycd .gt_indent_2 {
  text-indent: 10px;
}

#fwyttoiycd .gt_indent_3 {
  text-indent: 15px;
}

#fwyttoiycd .gt_indent_4 {
  text-indent: 20px;
}

#fwyttoiycd .gt_indent_5 {
  text-indent: 25px;
}

#fwyttoiycd .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#fwyttoiycd div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_mass</th>
<th id="mean_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper</th>
<th id="mean_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length</th>
<th id="mean_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth</th>
<th id="min_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_mass</th>
<th id="min_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper</th>
<th id="min_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length</th>
<th id="min_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth</th>
<th id="max_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_mass</th>
<th id="max_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper</th>
<th id="max_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length</th>
<th id="max_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth</th>
<th id="sd_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_mass</th>
<th id="sd_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper</th>
<th id="sd_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length</th>
<th id="sd_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth</th>
<th id="var_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_mass</th>
<th id="var_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper</th>
<th id="var_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length</th>
<th id="var_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth</th>
<th id="length_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_mass</th>
<th id="length_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper</th>
<th id="length_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length</th>
<th id="length_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth</th>
<th id="quantile_mass_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_mass_25</th>
<th id="quantile_flipper_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_flipper_25</th>
<th id="quantile_bill_length_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_length_25</th>
<th id="quantile_bill_depth_25" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_depth_25</th>
<th id="quantile_mass_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_mass_75</th>
<th id="quantile_flipper_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_flipper_75</th>
<th id="quantile_bill_length_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_length_75</th>
<th id="quantile_bill_depth_75" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">quantile_bill_depth_75</th>
<th id="iqr_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_mass</th>
<th id="iqr_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper</th>
<th id="iqr_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length</th>
<th id="iqr_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,700.66</td>
<td class="gt_row gt_right" headers="mean_flipper">189.95</td>
<td class="gt_row gt_right" headers="mean_bill_length">38.79</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.35</td>
<td class="gt_row gt_right" headers="min_mass">2,850.00</td>
<td class="gt_row gt_right" headers="min_flipper">172.00</td>
<td class="gt_row gt_right" headers="min_bill_length">32.10</td>
<td class="gt_row gt_right" headers="min_bill_depth">15.50</td>
<td class="gt_row gt_right" headers="max_mass">4,775.00</td>
<td class="gt_row gt_right" headers="max_flipper">210.00</td>
<td class="gt_row gt_right" headers="max_bill_length">46.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">21.50</td>
<td class="gt_row gt_right" headers="sd_mass">458.57</td>
<td class="gt_row gt_right" headers="sd_flipper">6.54</td>
<td class="gt_row gt_right" headers="sd_bill_length">2.66</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.22</td>
<td class="gt_row gt_right" headers="var_mass">210,282.89</td>
<td class="gt_row gt_right" headers="var_flipper">42.76</td>
<td class="gt_row gt_right" headers="var_bill_length">7.09</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.48</td>
<td class="gt_row gt_right" headers="length_mass">152.00</td>
<td class="gt_row gt_right" headers="length_flipper">152.00</td>
<td class="gt_row gt_right" headers="length_bill_length">152.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">152.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">3,350.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">186.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">36.75</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">17.50</td>
<td class="gt_row gt_right" headers="quantile_mass_75">4,000.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">195.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">40.75</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">19.00</td>
<td class="gt_row gt_right" headers="iqr_mass">650.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_mass">5,076.02</td>
<td class="gt_row gt_right" headers="mean_flipper">217.19</td>
<td class="gt_row gt_right" headers="mean_bill_length">47.50</td>
<td class="gt_row gt_right" headers="mean_bill_depth">14.98</td>
<td class="gt_row gt_right" headers="min_mass">3,950.00</td>
<td class="gt_row gt_right" headers="min_flipper">203.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">13.10</td>
<td class="gt_row gt_right" headers="max_mass">6,300.00</td>
<td class="gt_row gt_right" headers="max_flipper">231.00</td>
<td class="gt_row gt_right" headers="max_bill_length">59.60</td>
<td class="gt_row gt_right" headers="max_bill_depth">17.30</td>
<td class="gt_row gt_right" headers="sd_mass">504.12</td>
<td class="gt_row gt_right" headers="sd_flipper">6.48</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.08</td>
<td class="gt_row gt_right" headers="sd_bill_depth">0.98</td>
<td class="gt_row gt_right" headers="var_mass">254,133.18</td>
<td class="gt_row gt_right" headers="var_flipper">42.05</td>
<td class="gt_row gt_right" headers="var_bill_length">9.50</td>
<td class="gt_row gt_right" headers="var_bill_depth">0.96</td>
<td class="gt_row gt_right" headers="length_mass">124.00</td>
<td class="gt_row gt_right" headers="length_flipper">124.00</td>
<td class="gt_row gt_right" headers="length_bill_length">124.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">124.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">4,700.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">212.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">45.30</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">14.20</td>
<td class="gt_row gt_right" headers="quantile_mass_75">5,500.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">221.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">49.55</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">15.70</td>
<td class="gt_row gt_right" headers="iqr_mass">800.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.25</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,733.09</td>
<td class="gt_row gt_right" headers="mean_flipper">195.82</td>
<td class="gt_row gt_right" headers="mean_bill_length">48.83</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.42</td>
<td class="gt_row gt_right" headers="min_mass">2,700.00</td>
<td class="gt_row gt_right" headers="min_flipper">178.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">16.40</td>
<td class="gt_row gt_right" headers="max_mass">4,800.00</td>
<td class="gt_row gt_right" headers="max_flipper">212.00</td>
<td class="gt_row gt_right" headers="max_bill_length">58.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">20.80</td>
<td class="gt_row gt_right" headers="sd_mass">384.34</td>
<td class="gt_row gt_right" headers="sd_flipper">7.13</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.34</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.14</td>
<td class="gt_row gt_right" headers="var_mass">147,713.45</td>
<td class="gt_row gt_right" headers="var_flipper">50.86</td>
<td class="gt_row gt_right" headers="var_bill_length">11.15</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.29</td>
<td class="gt_row gt_right" headers="length_mass">68.00</td>
<td class="gt_row gt_right" headers="length_flipper">68.00</td>
<td class="gt_row gt_right" headers="length_bill_length">68.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">68.00</td>
<td class="gt_row gt_right" headers="quantile_mass_25">3,487.50</td>
<td class="gt_row gt_right" headers="quantile_flipper_25">191.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_25">46.35</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_25">17.50</td>
<td class="gt_row gt_right" headers="quantile_mass_75">3,950.00</td>
<td class="gt_row gt_right" headers="quantile_flipper_75">201.00</td>
<td class="gt_row gt_right" headers="quantile_bill_length_75">51.08</td>
<td class="gt_row gt_right" headers="quantile_bill_depth_75">19.40</td>
<td class="gt_row gt_right" headers="iqr_mass">462.50</td>
<td class="gt_row gt_right" headers="iqr_flipper">10.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.73</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.90</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>for loop for species: 0.049 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, the for loop over species took approximately 2.362 seconds.</p>
</section>
<section id="approach-2.2-looping-over-functions" class="level3" data-number="5.2">
<h3 data-number="5.2" class="anchored" data-anchor-id="approach-2.2-looping-over-functions"><span class="header-section-number">5.2</span> Approach 2.2: Looping over functions</h3>
<p>A loop over functions abstracts a different dimension of the problem. Instead of writing <code>mean()</code>, <code>min()</code>, <code>max()</code>, <code>sd()</code>, and the other functions repeatedly by hand, we store the functions in a list and apply each one systematically. The grouping by species is still handled by <code>dplyr</code>.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loop over functions"</span>)</span>
<span id="cb8-2"></span>
<span id="cb8-3">summary_funs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb8-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd     =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb8-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb8-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb8-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb8-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb8-13">)</span>
<span id="cb8-14"></span>
<span id="cb8-15">measure_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb8-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mass        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>,</span>
<span id="cb8-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">flipper    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>,</span>
<span id="cb8-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bill_length =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_length_mm"</span>,</span>
<span id="cb8-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bill_depth  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_depth_mm"</span></span>
<span id="cb8-20">)</span>
<span id="cb8-21"></span>
<span id="cb8-22">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb8-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb8-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb8-27">  )</span>
<span id="cb8-28"></span>
<span id="cb8-29"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (fun_name <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(summary_funs)) {</span>
<span id="cb8-30">  fun_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_funs[[fun_name]]</span>
<span id="cb8-31"></span>
<span id="cb8-32">  stats_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-34">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb8-35">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(</span>
<span id="cb8-36">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(measure_vars),</span>
<span id="cb8-37">        fun_i,</span>
<span id="cb8-38">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(fun_name, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_{.col}"</span>)</span>
<span id="cb8-39">      ),</span>
<span id="cb8-40">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb8-41">    )</span>
<span id="cb8-42"></span>
<span id="cb8-43">  p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-44">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(stats_i, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span>)</span>
<span id="cb8-45">}</span>
<span id="cb8-46"></span>
<span id="cb8-47">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb8-50">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb8-51">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-52">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb8-53">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fakkqquriz" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#fakkqquriz table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#fakkqquriz thead, #fakkqquriz tbody, #fakkqquriz tfoot, #fakkqquriz tr, #fakkqquriz td, #fakkqquriz th {
  border-style: none;
}

#fakkqquriz p {
  margin: 0;
  padding: 0;
}

#fakkqquriz .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#fakkqquriz .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#fakkqquriz .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#fakkqquriz .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#fakkqquriz .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#fakkqquriz .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fakkqquriz .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#fakkqquriz .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#fakkqquriz .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#fakkqquriz .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#fakkqquriz .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#fakkqquriz .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#fakkqquriz .gt_spanner_row {
  border-bottom-style: hidden;
}

#fakkqquriz .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#fakkqquriz .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#fakkqquriz .gt_from_md > :first-child {
  margin-top: 0;
}

#fakkqquriz .gt_from_md > :last-child {
  margin-bottom: 0;
}

#fakkqquriz .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#fakkqquriz .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#fakkqquriz .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#fakkqquriz .gt_row_group_first td {
  border-top-width: 2px;
}

#fakkqquriz .gt_row_group_first th {
  border-top-width: 2px;
}

#fakkqquriz .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#fakkqquriz .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#fakkqquriz .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#fakkqquriz .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fakkqquriz .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#fakkqquriz .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#fakkqquriz .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#fakkqquriz .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#fakkqquriz .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#fakkqquriz .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#fakkqquriz .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#fakkqquriz .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#fakkqquriz .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#fakkqquriz .gt_left {
  text-align: left;
}

#fakkqquriz .gt_center {
  text-align: center;
}

#fakkqquriz .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#fakkqquriz .gt_font_normal {
  font-weight: normal;
}

#fakkqquriz .gt_font_bold {
  font-weight: bold;
}

#fakkqquriz .gt_font_italic {
  font-style: italic;
}

#fakkqquriz .gt_super {
  font-size: 65%;
}

#fakkqquriz .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#fakkqquriz .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#fakkqquriz .gt_indent_1 {
  text-indent: 5px;
}

#fakkqquriz .gt_indent_2 {
  text-indent: 10px;
}

#fakkqquriz .gt_indent_3 {
  text-indent: 15px;
}

#fakkqquriz .gt_indent_4 {
  text-indent: 20px;
}

#fakkqquriz .gt_indent_5 {
  text-indent: 25px;
}

#fakkqquriz .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#fakkqquriz div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_mass</th>
<th id="mean_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper</th>
<th id="mean_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length</th>
<th id="mean_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth</th>
<th id="min_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_mass</th>
<th id="min_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper</th>
<th id="min_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length</th>
<th id="min_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth</th>
<th id="max_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_mass</th>
<th id="max_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper</th>
<th id="max_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length</th>
<th id="max_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth</th>
<th id="sd_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_mass</th>
<th id="sd_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper</th>
<th id="sd_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length</th>
<th id="sd_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth</th>
<th id="var_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_mass</th>
<th id="var_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper</th>
<th id="var_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length</th>
<th id="var_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth</th>
<th id="length_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_mass</th>
<th id="length_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper</th>
<th id="length_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length</th>
<th id="length_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth</th>
<th id="q25_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_mass</th>
<th id="q25_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_flipper</th>
<th id="q25_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_length</th>
<th id="q25_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_depth</th>
<th id="q75_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_mass</th>
<th id="q75_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_flipper</th>
<th id="q75_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_length</th>
<th id="q75_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_depth</th>
<th id="iqr_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_mass</th>
<th id="iqr_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper</th>
<th id="iqr_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length</th>
<th id="iqr_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,700.66</td>
<td class="gt_row gt_right" headers="mean_flipper">189.95</td>
<td class="gt_row gt_right" headers="mean_bill_length">38.79</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.35</td>
<td class="gt_row gt_right" headers="min_mass">2,850.00</td>
<td class="gt_row gt_right" headers="min_flipper">172.00</td>
<td class="gt_row gt_right" headers="min_bill_length">32.10</td>
<td class="gt_row gt_right" headers="min_bill_depth">15.50</td>
<td class="gt_row gt_right" headers="max_mass">4,775.00</td>
<td class="gt_row gt_right" headers="max_flipper">210.00</td>
<td class="gt_row gt_right" headers="max_bill_length">46.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">21.50</td>
<td class="gt_row gt_right" headers="sd_mass">458.57</td>
<td class="gt_row gt_right" headers="sd_flipper">6.54</td>
<td class="gt_row gt_right" headers="sd_bill_length">2.66</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.22</td>
<td class="gt_row gt_right" headers="var_mass">210,282.89</td>
<td class="gt_row gt_right" headers="var_flipper">42.76</td>
<td class="gt_row gt_right" headers="var_bill_length">7.09</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.48</td>
<td class="gt_row gt_right" headers="length_mass">152.00</td>
<td class="gt_row gt_right" headers="length_flipper">152.00</td>
<td class="gt_row gt_right" headers="length_bill_length">152.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">152.00</td>
<td class="gt_row gt_right" headers="q25_mass">3,350.00</td>
<td class="gt_row gt_right" headers="q25_flipper">186.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">36.75</td>
<td class="gt_row gt_right" headers="q25_bill_depth">17.50</td>
<td class="gt_row gt_right" headers="q75_mass">4,000.00</td>
<td class="gt_row gt_right" headers="q75_flipper">195.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">40.75</td>
<td class="gt_row gt_right" headers="q75_bill_depth">19.00</td>
<td class="gt_row gt_right" headers="iqr_mass">650.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,733.09</td>
<td class="gt_row gt_right" headers="mean_flipper">195.82</td>
<td class="gt_row gt_right" headers="mean_bill_length">48.83</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.42</td>
<td class="gt_row gt_right" headers="min_mass">2,700.00</td>
<td class="gt_row gt_right" headers="min_flipper">178.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">16.40</td>
<td class="gt_row gt_right" headers="max_mass">4,800.00</td>
<td class="gt_row gt_right" headers="max_flipper">212.00</td>
<td class="gt_row gt_right" headers="max_bill_length">58.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">20.80</td>
<td class="gt_row gt_right" headers="sd_mass">384.34</td>
<td class="gt_row gt_right" headers="sd_flipper">7.13</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.34</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.14</td>
<td class="gt_row gt_right" headers="var_mass">147,713.45</td>
<td class="gt_row gt_right" headers="var_flipper">50.86</td>
<td class="gt_row gt_right" headers="var_bill_length">11.15</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.29</td>
<td class="gt_row gt_right" headers="length_mass">68.00</td>
<td class="gt_row gt_right" headers="length_flipper">68.00</td>
<td class="gt_row gt_right" headers="length_bill_length">68.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">68.00</td>
<td class="gt_row gt_right" headers="q25_mass">3,487.50</td>
<td class="gt_row gt_right" headers="q25_flipper">191.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">46.35</td>
<td class="gt_row gt_right" headers="q25_bill_depth">17.50</td>
<td class="gt_row gt_right" headers="q75_mass">3,950.00</td>
<td class="gt_row gt_right" headers="q75_flipper">201.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">51.08</td>
<td class="gt_row gt_right" headers="q75_bill_depth">19.40</td>
<td class="gt_row gt_right" headers="iqr_mass">462.50</td>
<td class="gt_row gt_right" headers="iqr_flipper">10.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.73</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.90</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_mass">5,076.02</td>
<td class="gt_row gt_right" headers="mean_flipper">217.19</td>
<td class="gt_row gt_right" headers="mean_bill_length">47.50</td>
<td class="gt_row gt_right" headers="mean_bill_depth">14.98</td>
<td class="gt_row gt_right" headers="min_mass">3,950.00</td>
<td class="gt_row gt_right" headers="min_flipper">203.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">13.10</td>
<td class="gt_row gt_right" headers="max_mass">6,300.00</td>
<td class="gt_row gt_right" headers="max_flipper">231.00</td>
<td class="gt_row gt_right" headers="max_bill_length">59.60</td>
<td class="gt_row gt_right" headers="max_bill_depth">17.30</td>
<td class="gt_row gt_right" headers="sd_mass">504.12</td>
<td class="gt_row gt_right" headers="sd_flipper">6.48</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.08</td>
<td class="gt_row gt_right" headers="sd_bill_depth">0.98</td>
<td class="gt_row gt_right" headers="var_mass">254,133.18</td>
<td class="gt_row gt_right" headers="var_flipper">42.05</td>
<td class="gt_row gt_right" headers="var_bill_length">9.50</td>
<td class="gt_row gt_right" headers="var_bill_depth">0.96</td>
<td class="gt_row gt_right" headers="length_mass">124.00</td>
<td class="gt_row gt_right" headers="length_flipper">124.00</td>
<td class="gt_row gt_right" headers="length_bill_length">124.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">124.00</td>
<td class="gt_row gt_right" headers="q25_mass">4,700.00</td>
<td class="gt_row gt_right" headers="q25_flipper">212.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">45.30</td>
<td class="gt_row gt_right" headers="q25_bill_depth">14.20</td>
<td class="gt_row gt_right" headers="q75_mass">5,500.00</td>
<td class="gt_row gt_right" headers="q75_flipper">221.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">49.55</td>
<td class="gt_row gt_right" headers="q75_bill_depth">15.70</td>
<td class="gt_row gt_right" headers="iqr_mass">800.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.25</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>loop over functions: 0.05 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, the loop over functions took approximately 3.188 seconds.</p>
</section>
<section id="approach-2.3-looping-over-species-functions-and-variables" class="level3" data-number="5.3">
<h3 data-number="5.3" class="anchored" data-anchor-id="approach-2.3-looping-over-species-functions-and-variables"><span class="header-section-number">5.3</span> Approach 2.3: Looping over species, functions, and variables</h3>
<p>The nested-loop version makes the full computational structure visible. For each species, for each summary function, and for each measurement variable, the code calculates one value and stores it in a named output column.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"for loop over species and functions"</span>)</span>
<span id="cb11-2"></span>
<span id="cb11-3">summary_funs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb11-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd     =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb11-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb11-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb11-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb11-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb11-13">)</span>
<span id="cb11-14"></span>
<span id="cb11-15">measure_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb11-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mass        =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>,</span>
<span id="cb11-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">flipper    =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>,</span>
<span id="cb11-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bill_length =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_length_mm"</span>,</span>
<span id="cb11-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bill_depth  =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_depth_mm"</span></span>
<span id="cb11-20">)</span>
<span id="cb11-21"></span>
<span id="cb11-22">species_values <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(penguins<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>species)</span>
<span id="cb11-23"></span>
<span id="cb11-24">results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(species_values))</span>
<span id="cb11-25"></span>
<span id="cb11-26"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(species_values)) {</span>
<span id="cb11-27">  species_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> species_values[[i]]</span>
<span id="cb11-28"></span>
<span id="cb11-29">  data_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(species <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> species_i)</span>
<span id="cb11-31"></span>
<span id="cb11-32">  row_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb11-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> species_i,</span>
<span id="cb11-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(data_i)</span>
<span id="cb11-35">  )</span>
<span id="cb11-36"></span>
<span id="cb11-37">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (fun_name <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(summary_funs)) {</span>
<span id="cb11-38">    fun_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> summary_funs[[fun_name]]</span>
<span id="cb11-39"></span>
<span id="cb11-40">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (var_label <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(measure_vars)) {</span>
<span id="cb11-41">      var_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> measure_vars[[var_label]]</span>
<span id="cb11-42"></span>
<span id="cb11-43">      output_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(fun_name, var_label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>)</span>
<span id="cb11-44"></span>
<span id="cb11-45">      row_i[[output_name]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fun_i</span>(data_i[[var_name]])</span>
<span id="cb11-46">    }</span>
<span id="cb11-47">  }</span>
<span id="cb11-48"></span>
<span id="cb11-49">  results[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>(row_i)</span>
<span id="cb11-50">}</span>
<span id="cb11-51"></span>
<span id="cb11-52">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(results)</span>
<span id="cb11-53"></span>
<span id="cb11-54">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb11-57">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb11-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb11-59">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb11-60">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="edysynwlwt" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#edysynwlwt table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#edysynwlwt thead, #edysynwlwt tbody, #edysynwlwt tfoot, #edysynwlwt tr, #edysynwlwt td, #edysynwlwt th {
  border-style: none;
}

#edysynwlwt p {
  margin: 0;
  padding: 0;
}

#edysynwlwt .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#edysynwlwt .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#edysynwlwt .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#edysynwlwt .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#edysynwlwt .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#edysynwlwt .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#edysynwlwt .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#edysynwlwt .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#edysynwlwt .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#edysynwlwt .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#edysynwlwt .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#edysynwlwt .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#edysynwlwt .gt_spanner_row {
  border-bottom-style: hidden;
}

#edysynwlwt .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#edysynwlwt .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#edysynwlwt .gt_from_md > :first-child {
  margin-top: 0;
}

#edysynwlwt .gt_from_md > :last-child {
  margin-bottom: 0;
}

#edysynwlwt .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#edysynwlwt .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#edysynwlwt .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#edysynwlwt .gt_row_group_first td {
  border-top-width: 2px;
}

#edysynwlwt .gt_row_group_first th {
  border-top-width: 2px;
}

#edysynwlwt .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#edysynwlwt .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#edysynwlwt .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#edysynwlwt .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#edysynwlwt .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#edysynwlwt .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#edysynwlwt .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#edysynwlwt .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#edysynwlwt .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#edysynwlwt .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#edysynwlwt .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#edysynwlwt .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#edysynwlwt .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#edysynwlwt .gt_left {
  text-align: left;
}

#edysynwlwt .gt_center {
  text-align: center;
}

#edysynwlwt .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#edysynwlwt .gt_font_normal {
  font-weight: normal;
}

#edysynwlwt .gt_font_bold {
  font-weight: bold;
}

#edysynwlwt .gt_font_italic {
  font-style: italic;
}

#edysynwlwt .gt_super {
  font-size: 65%;
}

#edysynwlwt .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#edysynwlwt .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#edysynwlwt .gt_indent_1 {
  text-indent: 5px;
}

#edysynwlwt .gt_indent_2 {
  text-indent: 10px;
}

#edysynwlwt .gt_indent_3 {
  text-indent: 15px;
}

#edysynwlwt .gt_indent_4 {
  text-indent: 20px;
}

#edysynwlwt .gt_indent_5 {
  text-indent: 25px;
}

#edysynwlwt .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#edysynwlwt div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_mass</th>
<th id="mean_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper</th>
<th id="mean_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length</th>
<th id="mean_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth</th>
<th id="min_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_mass</th>
<th id="min_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper</th>
<th id="min_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length</th>
<th id="min_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth</th>
<th id="max_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_mass</th>
<th id="max_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper</th>
<th id="max_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length</th>
<th id="max_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth</th>
<th id="sd_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_mass</th>
<th id="sd_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper</th>
<th id="sd_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length</th>
<th id="sd_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth</th>
<th id="var_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_mass</th>
<th id="var_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper</th>
<th id="var_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length</th>
<th id="var_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth</th>
<th id="length_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_mass</th>
<th id="length_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper</th>
<th id="length_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length</th>
<th id="length_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth</th>
<th id="q25_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_mass</th>
<th id="q25_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_flipper</th>
<th id="q25_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_length</th>
<th id="q25_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_depth</th>
<th id="q75_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_mass</th>
<th id="q75_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_flipper</th>
<th id="q75_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_length</th>
<th id="q75_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_depth</th>
<th id="iqr_mass" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_mass</th>
<th id="iqr_flipper" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper</th>
<th id="iqr_bill_length" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length</th>
<th id="iqr_bill_depth" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,700.66</td>
<td class="gt_row gt_right" headers="mean_flipper">189.95</td>
<td class="gt_row gt_right" headers="mean_bill_length">38.79</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.35</td>
<td class="gt_row gt_right" headers="min_mass">2,850.00</td>
<td class="gt_row gt_right" headers="min_flipper">172.00</td>
<td class="gt_row gt_right" headers="min_bill_length">32.10</td>
<td class="gt_row gt_right" headers="min_bill_depth">15.50</td>
<td class="gt_row gt_right" headers="max_mass">4,775.00</td>
<td class="gt_row gt_right" headers="max_flipper">210.00</td>
<td class="gt_row gt_right" headers="max_bill_length">46.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">21.50</td>
<td class="gt_row gt_right" headers="sd_mass">458.57</td>
<td class="gt_row gt_right" headers="sd_flipper">6.54</td>
<td class="gt_row gt_right" headers="sd_bill_length">2.66</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.22</td>
<td class="gt_row gt_right" headers="var_mass">210,282.89</td>
<td class="gt_row gt_right" headers="var_flipper">42.76</td>
<td class="gt_row gt_right" headers="var_bill_length">7.09</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.48</td>
<td class="gt_row gt_right" headers="length_mass">152.00</td>
<td class="gt_row gt_right" headers="length_flipper">152.00</td>
<td class="gt_row gt_right" headers="length_bill_length">152.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">152.00</td>
<td class="gt_row gt_right" headers="q25_mass">3,350.00</td>
<td class="gt_row gt_right" headers="q25_flipper">186.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">36.75</td>
<td class="gt_row gt_right" headers="q25_bill_depth">17.50</td>
<td class="gt_row gt_right" headers="q75_mass">4,000.00</td>
<td class="gt_row gt_right" headers="q75_flipper">195.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">40.75</td>
<td class="gt_row gt_right" headers="q75_bill_depth">19.00</td>
<td class="gt_row gt_right" headers="iqr_mass">650.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_mass">5,076.02</td>
<td class="gt_row gt_right" headers="mean_flipper">217.19</td>
<td class="gt_row gt_right" headers="mean_bill_length">47.50</td>
<td class="gt_row gt_right" headers="mean_bill_depth">14.98</td>
<td class="gt_row gt_right" headers="min_mass">3,950.00</td>
<td class="gt_row gt_right" headers="min_flipper">203.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">13.10</td>
<td class="gt_row gt_right" headers="max_mass">6,300.00</td>
<td class="gt_row gt_right" headers="max_flipper">231.00</td>
<td class="gt_row gt_right" headers="max_bill_length">59.60</td>
<td class="gt_row gt_right" headers="max_bill_depth">17.30</td>
<td class="gt_row gt_right" headers="sd_mass">504.12</td>
<td class="gt_row gt_right" headers="sd_flipper">6.48</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.08</td>
<td class="gt_row gt_right" headers="sd_bill_depth">0.98</td>
<td class="gt_row gt_right" headers="var_mass">254,133.18</td>
<td class="gt_row gt_right" headers="var_flipper">42.05</td>
<td class="gt_row gt_right" headers="var_bill_length">9.50</td>
<td class="gt_row gt_right" headers="var_bill_depth">0.96</td>
<td class="gt_row gt_right" headers="length_mass">124.00</td>
<td class="gt_row gt_right" headers="length_flipper">124.00</td>
<td class="gt_row gt_right" headers="length_bill_length">124.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">124.00</td>
<td class="gt_row gt_right" headers="q25_mass">4,700.00</td>
<td class="gt_row gt_right" headers="q25_flipper">212.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">45.30</td>
<td class="gt_row gt_right" headers="q25_bill_depth">14.20</td>
<td class="gt_row gt_right" headers="q75_mass">5,500.00</td>
<td class="gt_row gt_right" headers="q75_flipper">221.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">49.55</td>
<td class="gt_row gt_right" headers="q75_bill_depth">15.70</td>
<td class="gt_row gt_right" headers="iqr_mass">800.00</td>
<td class="gt_row gt_right" headers="iqr_flipper">9.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.25</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.50</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_mass">3,733.09</td>
<td class="gt_row gt_right" headers="mean_flipper">195.82</td>
<td class="gt_row gt_right" headers="mean_bill_length">48.83</td>
<td class="gt_row gt_right" headers="mean_bill_depth">18.42</td>
<td class="gt_row gt_right" headers="min_mass">2,700.00</td>
<td class="gt_row gt_right" headers="min_flipper">178.00</td>
<td class="gt_row gt_right" headers="min_bill_length">40.90</td>
<td class="gt_row gt_right" headers="min_bill_depth">16.40</td>
<td class="gt_row gt_right" headers="max_mass">4,800.00</td>
<td class="gt_row gt_right" headers="max_flipper">212.00</td>
<td class="gt_row gt_right" headers="max_bill_length">58.00</td>
<td class="gt_row gt_right" headers="max_bill_depth">20.80</td>
<td class="gt_row gt_right" headers="sd_mass">384.34</td>
<td class="gt_row gt_right" headers="sd_flipper">7.13</td>
<td class="gt_row gt_right" headers="sd_bill_length">3.34</td>
<td class="gt_row gt_right" headers="sd_bill_depth">1.14</td>
<td class="gt_row gt_right" headers="var_mass">147,713.45</td>
<td class="gt_row gt_right" headers="var_flipper">50.86</td>
<td class="gt_row gt_right" headers="var_bill_length">11.15</td>
<td class="gt_row gt_right" headers="var_bill_depth">1.29</td>
<td class="gt_row gt_right" headers="length_mass">68.00</td>
<td class="gt_row gt_right" headers="length_flipper">68.00</td>
<td class="gt_row gt_right" headers="length_bill_length">68.00</td>
<td class="gt_row gt_right" headers="length_bill_depth">68.00</td>
<td class="gt_row gt_right" headers="q25_mass">3,487.50</td>
<td class="gt_row gt_right" headers="q25_flipper">191.00</td>
<td class="gt_row gt_right" headers="q25_bill_length">46.35</td>
<td class="gt_row gt_right" headers="q25_bill_depth">17.50</td>
<td class="gt_row gt_right" headers="q75_mass">3,950.00</td>
<td class="gt_row gt_right" headers="q75_flipper">201.00</td>
<td class="gt_row gt_right" headers="q75_bill_length">51.08</td>
<td class="gt_row gt_right" headers="q75_bill_depth">19.40</td>
<td class="gt_row gt_right" headers="iqr_mass">462.50</td>
<td class="gt_row gt_right" headers="iqr_flipper">10.00</td>
<td class="gt_row gt_right" headers="iqr_bill_length">4.73</td>
<td class="gt_row gt_right" headers="iqr_bill_depth">1.90</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>for loop over species and functions: 0.029 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, the nested loop over species, functions, and variables took approximately 2.466 seconds.</p>
<p>The explicit approach emphasizes readability by spelling everything out. The for-loop approaches emphasize the repeated structure of the computation. Looping over species highlights the grouping logic, looping over functions highlights the reusable summary operations, and looping over species, functions, and variables exposes the full grid of operations being performed. For production code, however, these loop-based versions require more bookkeeping than necessary for a simple grouped summary.</p>
</section>
</section>
<section id="approach-3-declarative-summaries-with-across" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="approach-3-declarative-summaries-with-across"><span class="header-section-number">6</span> Approach 3: Declarative summaries with <code>across()</code></h2>
<p>The <code>across()</code> approach is the recommended default for this example because the desired output is a tibble of scalar summaries. Instead of listing every computation manually, we declare the measurement columns and the summary functions, then let <code>summarize()</code> generate the combinations. This version is shorter, easier to maintain, and easier to scale up than the explicit or loop-based alternatives.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"`across` code"</span>)</span>
<span id="cb14-2"></span>
<span id="cb14-3">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb14-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb14-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(</span>
<span id="cb14-8">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb14-9">        body_mass_g,</span>
<span id="cb14-10">        flipper_length_mm,</span>
<span id="cb14-11">        bill_length_mm,</span>
<span id="cb14-12">        bill_depth_mm</span>
<span id="cb14-13">      ),</span>
<span id="cb14-14">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.fns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb14-15">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb14-16">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb14-17">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb14-18">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb14-19">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb14-20">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb14-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb14-22">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)),</span>
<span id="cb14-23">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr  =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb14-24">      ),</span>
<span id="cb14-25">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.names =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{.fn}_{.col}"</span></span>
<span id="cb14-26">    ),</span>
<span id="cb14-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb14-28">  )</span>
<span id="cb14-29"></span>
<span id="cb14-30">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb14-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb14-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb14-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb14-36">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="enbzivukwk" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#enbzivukwk table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#enbzivukwk thead, #enbzivukwk tbody, #enbzivukwk tfoot, #enbzivukwk tr, #enbzivukwk td, #enbzivukwk th {
  border-style: none;
}

#enbzivukwk p {
  margin: 0;
  padding: 0;
}

#enbzivukwk .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#enbzivukwk .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#enbzivukwk .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#enbzivukwk .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#enbzivukwk .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#enbzivukwk .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#enbzivukwk .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#enbzivukwk .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#enbzivukwk .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#enbzivukwk .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#enbzivukwk .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#enbzivukwk .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#enbzivukwk .gt_spanner_row {
  border-bottom-style: hidden;
}

#enbzivukwk .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#enbzivukwk .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#enbzivukwk .gt_from_md > :first-child {
  margin-top: 0;
}

#enbzivukwk .gt_from_md > :last-child {
  margin-bottom: 0;
}

#enbzivukwk .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#enbzivukwk .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#enbzivukwk .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#enbzivukwk .gt_row_group_first td {
  border-top-width: 2px;
}

#enbzivukwk .gt_row_group_first th {
  border-top-width: 2px;
}

#enbzivukwk .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#enbzivukwk .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#enbzivukwk .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#enbzivukwk .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#enbzivukwk .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#enbzivukwk .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#enbzivukwk .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#enbzivukwk .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#enbzivukwk .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#enbzivukwk .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#enbzivukwk .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#enbzivukwk .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#enbzivukwk .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#enbzivukwk .gt_left {
  text-align: left;
}

#enbzivukwk .gt_center {
  text-align: center;
}

#enbzivukwk .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#enbzivukwk .gt_font_normal {
  font-weight: normal;
}

#enbzivukwk .gt_font_bold {
  font-weight: bold;
}

#enbzivukwk .gt_font_italic {
  font-style: italic;
}

#enbzivukwk .gt_super {
  font-size: 65%;
}

#enbzivukwk .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#enbzivukwk .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#enbzivukwk .gt_indent_1 {
  text-indent: 5px;
}

#enbzivukwk .gt_indent_2 {
  text-indent: 10px;
}

#enbzivukwk .gt_indent_3 {
  text-indent: 15px;
}

#enbzivukwk .gt_indent_4 {
  text-indent: 20px;
}

#enbzivukwk .gt_indent_5 {
  text-indent: 25px;
}

#enbzivukwk .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#enbzivukwk div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_body_mass_g</th>
<th id="min_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_body_mass_g</th>
<th id="max_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_body_mass_g</th>
<th id="sd_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_body_mass_g</th>
<th id="var_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_body_mass_g</th>
<th id="length_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_body_mass_g</th>
<th id="q25_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_body_mass_g</th>
<th id="q75_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_body_mass_g</th>
<th id="iqr_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_body_mass_g</th>
<th id="mean_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper_length_mm</th>
<th id="min_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper_length_mm</th>
<th id="max_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper_length_mm</th>
<th id="sd_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper_length_mm</th>
<th id="var_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper_length_mm</th>
<th id="length_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper_length_mm</th>
<th id="q25_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_flipper_length_mm</th>
<th id="q75_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_flipper_length_mm</th>
<th id="iqr_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper_length_mm</th>
<th id="mean_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length_mm</th>
<th id="min_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length_mm</th>
<th id="max_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length_mm</th>
<th id="sd_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length_mm</th>
<th id="var_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length_mm</th>
<th id="length_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length_mm</th>
<th id="q25_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_length_mm</th>
<th id="q75_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_length_mm</th>
<th id="iqr_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length_mm</th>
<th id="mean_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth_mm</th>
<th id="min_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth_mm</th>
<th id="max_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth_mm</th>
<th id="sd_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth_mm</th>
<th id="var_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth_mm</th>
<th id="length_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth_mm</th>
<th id="q25_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_depth_mm</th>
<th id="q75_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_depth_mm</th>
<th id="iqr_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth_mm</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,700.66</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,850.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,775.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">458.57</td>
<td class="gt_row gt_right" headers="var_body_mass_g">210,282.89</td>
<td class="gt_row gt_right" headers="length_body_mass_g">152.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,350.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">4,000.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">650.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">189.95</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">172.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">210.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.54</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.76</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">186.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">195.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">38.79</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">32.10</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">46.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">2.66</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">7.09</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">36.75</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">40.75</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.00</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.35</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">15.50</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">21.50</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.22</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.48</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,733.09</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,700.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,800.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">384.34</td>
<td class="gt_row gt_right" headers="var_body_mass_g">147,713.45</td>
<td class="gt_row gt_right" headers="length_body_mass_g">68.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,487.50</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">462.50</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">195.82</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">178.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">7.13</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">50.86</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">191.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">201.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">10.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">48.83</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">58.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.34</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">11.15</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">46.35</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">51.08</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.73</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.42</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">16.40</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">20.80</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.14</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.29</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.40</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.90</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">5,076.02</td>
<td class="gt_row gt_right" headers="min_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">6,300.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">504.12</td>
<td class="gt_row gt_right" headers="var_body_mass_g">254,133.18</td>
<td class="gt_row gt_right" headers="length_body_mass_g">124.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">4,700.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">5,500.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">800.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">217.19</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">203.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">231.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.48</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.05</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">221.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">47.50</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">59.60</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.08</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">9.50</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">45.30</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">49.55</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.25</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">14.98</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">13.10</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">17.30</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">0.98</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">0.96</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">14.20</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">15.70</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>`across` code: 0.029 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, for the extended Penguin dataset consisting of 344 rows and 8 columns, the declarative <code>across()</code> approach took approximately 2.059 seconds to run. In this run, it was fractionally slower than the fully explicit version, but it is easier to read, easier to maintain, and easier to extend. Adding or removing a calculation requires changing the function list, not rewriting the entire summary.</p>
</section>
<section id="approach-4-per-group-data-frame-workflows-with-group_modify" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="approach-4-per-group-data-frame-workflows-with-group_modify"><span class="header-section-number">7</span> Approach 4: Per-group data-frame workflows with <code>group_modify()</code></h2>
<p>After writing the summaries explicitly and then refactoring them with <code>across()</code>, we can take one more step toward a reusable split-apply-combine workflow with <code>group_modify()</code>. The explicit version lists every calculation one by one, while the <code>across()</code> version declares a set of columns and a set of functions to apply inside <code>summarize()</code>. <code>group_modify()</code> shifts the focus from applying functions across columns to applying a function across groups.</p>
<p>For each group, <code>dplyr</code> passes two objects to the function: <code>.x</code>, the subset of rows for that group, and <code>.y</code>, a one-row tibble containing the group key. Because the function must return a data frame, <code>group_modify()</code> is best suited for cases where each group needs a custom “data frame in, data frame out” analysis that is more involved than a standard <code>summarize()</code> call.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group modify approach"</span>)</span>
<span id="cb17-2"></span>
<span id="cb17-3">summary_funs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb17-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd     =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb17-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb17-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb17-13">)</span>
<span id="cb17-14"></span>
<span id="cb17-15">measure_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb17-16">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>,</span>
<span id="cb17-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>,</span>
<span id="cb17-18">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_length_mm"</span>,</span>
<span id="cb17-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_depth_mm"</span></span>
<span id="cb17-20">)</span>
<span id="cb17-21"></span>
<span id="cb17-22">summarize_one_species <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb17-23">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-24">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb17-25">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb17-26">      dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(</span>
<span id="cb17-27">        dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(measure_vars),</span>
<span id="cb17-28">        summary_funs,</span>
<span id="cb17-29">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.names =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{.fn}_{.col}"</span></span>
<span id="cb17-30">      ),</span>
<span id="cb17-31">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb17-32">    )</span>
<span id="cb17-33">}</span>
<span id="cb17-34"></span>
<span id="cb17-35">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-36">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-37">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_modify</span>(\(.x, .y) {</span>
<span id="cb17-38">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize_one_species</span>(.x)</span>
<span id="cb17-39">  }) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-40">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb17-41"></span>
<span id="cb17-42">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb17-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb17-45">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb17-46">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb17-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb17-48">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="jcxplucyxy" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#jcxplucyxy table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#jcxplucyxy thead, #jcxplucyxy tbody, #jcxplucyxy tfoot, #jcxplucyxy tr, #jcxplucyxy td, #jcxplucyxy th {
  border-style: none;
}

#jcxplucyxy p {
  margin: 0;
  padding: 0;
}

#jcxplucyxy .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#jcxplucyxy .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#jcxplucyxy .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#jcxplucyxy .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#jcxplucyxy .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#jcxplucyxy .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#jcxplucyxy .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#jcxplucyxy .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#jcxplucyxy .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#jcxplucyxy .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#jcxplucyxy .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#jcxplucyxy .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#jcxplucyxy .gt_spanner_row {
  border-bottom-style: hidden;
}

#jcxplucyxy .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#jcxplucyxy .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#jcxplucyxy .gt_from_md > :first-child {
  margin-top: 0;
}

#jcxplucyxy .gt_from_md > :last-child {
  margin-bottom: 0;
}

#jcxplucyxy .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#jcxplucyxy .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#jcxplucyxy .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#jcxplucyxy .gt_row_group_first td {
  border-top-width: 2px;
}

#jcxplucyxy .gt_row_group_first th {
  border-top-width: 2px;
}

#jcxplucyxy .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#jcxplucyxy .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#jcxplucyxy .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#jcxplucyxy .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#jcxplucyxy .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#jcxplucyxy .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#jcxplucyxy .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#jcxplucyxy .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#jcxplucyxy .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#jcxplucyxy .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#jcxplucyxy .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#jcxplucyxy .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#jcxplucyxy .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#jcxplucyxy .gt_left {
  text-align: left;
}

#jcxplucyxy .gt_center {
  text-align: center;
}

#jcxplucyxy .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#jcxplucyxy .gt_font_normal {
  font-weight: normal;
}

#jcxplucyxy .gt_font_bold {
  font-weight: bold;
}

#jcxplucyxy .gt_font_italic {
  font-style: italic;
}

#jcxplucyxy .gt_super {
  font-size: 65%;
}

#jcxplucyxy .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#jcxplucyxy .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#jcxplucyxy .gt_indent_1 {
  text-indent: 5px;
}

#jcxplucyxy .gt_indent_2 {
  text-indent: 10px;
}

#jcxplucyxy .gt_indent_3 {
  text-indent: 15px;
}

#jcxplucyxy .gt_indent_4 {
  text-indent: 20px;
}

#jcxplucyxy .gt_indent_5 {
  text-indent: 25px;
}

#jcxplucyxy .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#jcxplucyxy div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_body_mass_g</th>
<th id="min_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_body_mass_g</th>
<th id="max_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_body_mass_g</th>
<th id="sd_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_body_mass_g</th>
<th id="var_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_body_mass_g</th>
<th id="length_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_body_mass_g</th>
<th id="q25_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_body_mass_g</th>
<th id="q75_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_body_mass_g</th>
<th id="iqr_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_body_mass_g</th>
<th id="mean_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper_length_mm</th>
<th id="min_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper_length_mm</th>
<th id="max_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper_length_mm</th>
<th id="sd_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper_length_mm</th>
<th id="var_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper_length_mm</th>
<th id="length_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper_length_mm</th>
<th id="q25_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_flipper_length_mm</th>
<th id="q75_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_flipper_length_mm</th>
<th id="iqr_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper_length_mm</th>
<th id="mean_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length_mm</th>
<th id="min_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length_mm</th>
<th id="max_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length_mm</th>
<th id="sd_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length_mm</th>
<th id="var_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length_mm</th>
<th id="length_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length_mm</th>
<th id="q25_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_length_mm</th>
<th id="q75_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_length_mm</th>
<th id="iqr_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length_mm</th>
<th id="mean_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth_mm</th>
<th id="min_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth_mm</th>
<th id="max_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth_mm</th>
<th id="sd_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth_mm</th>
<th id="var_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth_mm</th>
<th id="length_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth_mm</th>
<th id="q25_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_depth_mm</th>
<th id="q75_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_depth_mm</th>
<th id="iqr_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth_mm</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,700.66</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,850.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,775.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">458.57</td>
<td class="gt_row gt_right" headers="var_body_mass_g">210,282.89</td>
<td class="gt_row gt_right" headers="length_body_mass_g">152.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,350.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">4,000.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">650.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">189.95</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">172.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">210.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.54</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.76</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">186.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">195.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">38.79</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">32.10</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">46.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">2.66</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">7.09</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">36.75</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">40.75</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.00</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.35</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">15.50</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">21.50</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.22</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.48</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,733.09</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,700.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,800.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">384.34</td>
<td class="gt_row gt_right" headers="var_body_mass_g">147,713.45</td>
<td class="gt_row gt_right" headers="length_body_mass_g">68.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,487.50</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">462.50</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">195.82</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">178.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">7.13</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">50.86</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">191.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">201.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">10.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">48.83</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">58.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.34</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">11.15</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">46.35</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">51.08</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.73</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.42</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">16.40</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">20.80</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.14</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.29</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.40</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.90</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">5,076.02</td>
<td class="gt_row gt_right" headers="min_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">6,300.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">504.12</td>
<td class="gt_row gt_right" headers="var_body_mass_g">254,133.18</td>
<td class="gt_row gt_right" headers="length_body_mass_g">124.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">4,700.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">5,500.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">800.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">217.19</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">203.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">231.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.48</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.05</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">221.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">47.50</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">59.60</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.08</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">9.50</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">45.30</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">49.55</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.25</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">14.98</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">13.10</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">17.30</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">0.98</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">0.96</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">14.20</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">15.70</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Group modify approach: 0.036 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, the <code>group_modify()</code> approach took approximately 2.262 seconds for the same dataset. In this example, it is slower than the simpler <code>across()</code> approach, and it does not provide much practical benefit because the output is still a straightforward summary table.</p>
<p>The reason to consider <code>group_modify()</code> is not speed. The main motivation is flexibility. <code>summarize()</code> is best suited for reducing each group to one row of scalar summaries. When each group needs to return a more complex data frame, <code>group_modify()</code> becomes a better fit. As a rule of thumb, use <code>group_modify()</code> when each group needs to go through a custom mini-pipeline and return a data frame.</p>
</section>
<section id="approach-5-split-apply-combine-workflows-with-map" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="approach-5-split-apply-combine-workflows-with-map"><span class="header-section-number">8</span> Approach 5: Split-apply-combine workflows with <code>map()</code></h2>
<p>The fifth approach uses <code>map()</code> to make the split-apply-combine pattern explicit. Instead of asking <code>dplyr</code> to keep the grouped workflow intact, we first split the data into separate pieces and then apply the same analysis function to each piece. In this example, each species becomes its own small data frame, and the same summary function is applied to each species-level subset.</p>
<p>This approach is more general than the previous ones, but it is not the most direct tool for this particular summary task. If all we need is one summary table with one row per species, <code>group_by()</code> plus <code>summarize()</code> plus <code>across()</code> is clearer and more idiomatic. Here, the purpose of introducing <code>map()</code> is not to make the code shorter. The purpose is to show a workflow pattern that becomes useful when each subset should be treated as an independent unit of analysis.</p>
<p>The structure of the workflow is:</p>
<ol type="1">
<li>Define a function that analyzes one subset of the data.</li>
<li>Split the larger dataset into smaller pieces.</li>
<li>Apply the function to each piece.</li>
<li>Combine the results.</li>
</ol>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"using map"</span>)</span>
<span id="cb20-2"></span>
<span id="cb20-3">summary_funs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb20-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd     =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb20-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb20-13">)</span>
<span id="cb20-14"></span>
<span id="cb20-15">measure_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb20-16">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>,</span>
<span id="cb20-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>,</span>
<span id="cb20-18">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_length_mm"</span>,</span>
<span id="cb20-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_depth_mm"</span></span>
<span id="cb20-20">)</span>
<span id="cb20-21"></span>
<span id="cb20-22">summarize_one_species <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb20-23">  species_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>species)</span>
<span id="cb20-24"></span>
<span id="cb20-25">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb20-27">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb20-28">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(</span>
<span id="cb20-29">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(measure_vars),</span>
<span id="cb20-30">        summary_funs,</span>
<span id="cb20-31">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.names =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{.fn}_{.col}"</span></span>
<span id="cb20-32">      ),</span>
<span id="cb20-33">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb20-34">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-35">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> species_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.before =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb20-36">}</span>
<span id="cb20-37"></span>
<span id="cb20-38">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_split</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(</span>
<span id="cb20-41">    summarize_one_species</span>
<span id="cb20-42">  )</span>
<span id="cb20-43"></span>
<span id="cb20-44">p_stats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gt</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fmt_number</span>(</span>
<span id="cb20-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">columns =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">where</span>(is.numeric),</span>
<span id="cb20-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decimals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb20-49">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_seps =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb20-50">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="xlmwiojscr" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#xlmwiojscr table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#xlmwiojscr thead, #xlmwiojscr tbody, #xlmwiojscr tfoot, #xlmwiojscr tr, #xlmwiojscr td, #xlmwiojscr th {
  border-style: none;
}

#xlmwiojscr p {
  margin: 0;
  padding: 0;
}

#xlmwiojscr .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#xlmwiojscr .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#xlmwiojscr .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#xlmwiojscr .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#xlmwiojscr .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#xlmwiojscr .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#xlmwiojscr .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#xlmwiojscr .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#xlmwiojscr .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#xlmwiojscr .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#xlmwiojscr .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#xlmwiojscr .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#xlmwiojscr .gt_spanner_row {
  border-bottom-style: hidden;
}

#xlmwiojscr .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#xlmwiojscr .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#xlmwiojscr .gt_from_md > :first-child {
  margin-top: 0;
}

#xlmwiojscr .gt_from_md > :last-child {
  margin-bottom: 0;
}

#xlmwiojscr .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#xlmwiojscr .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#xlmwiojscr .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#xlmwiojscr .gt_row_group_first td {
  border-top-width: 2px;
}

#xlmwiojscr .gt_row_group_first th {
  border-top-width: 2px;
}

#xlmwiojscr .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#xlmwiojscr .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#xlmwiojscr .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#xlmwiojscr .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#xlmwiojscr .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#xlmwiojscr .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#xlmwiojscr .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#xlmwiojscr .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#xlmwiojscr .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#xlmwiojscr .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#xlmwiojscr .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#xlmwiojscr .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#xlmwiojscr .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#xlmwiojscr .gt_left {
  text-align: left;
}

#xlmwiojscr .gt_center {
  text-align: center;
}

#xlmwiojscr .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#xlmwiojscr .gt_font_normal {
  font-weight: normal;
}

#xlmwiojscr .gt_font_bold {
  font-weight: bold;
}

#xlmwiojscr .gt_font_italic {
  font-style: italic;
}

#xlmwiojscr .gt_super {
  font-size: 65%;
}

#xlmwiojscr .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#xlmwiojscr .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#xlmwiojscr .gt_indent_1 {
  text-indent: 5px;
}

#xlmwiojscr .gt_indent_2 {
  text-indent: 10px;
}

#xlmwiojscr .gt_indent_3 {
  text-indent: 15px;
}

#xlmwiojscr .gt_indent_4 {
  text-indent: 20px;
}

#xlmwiojscr .gt_indent_5 {
  text-indent: 25px;
}

#xlmwiojscr .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#xlmwiojscr div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="species" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">species</th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">n</th>
<th id="mean_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_body_mass_g</th>
<th id="min_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_body_mass_g</th>
<th id="max_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_body_mass_g</th>
<th id="sd_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_body_mass_g</th>
<th id="var_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_body_mass_g</th>
<th id="length_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_body_mass_g</th>
<th id="q25_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_body_mass_g</th>
<th id="q75_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_body_mass_g</th>
<th id="iqr_body_mass_g" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_body_mass_g</th>
<th id="mean_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_flipper_length_mm</th>
<th id="min_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_flipper_length_mm</th>
<th id="max_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_flipper_length_mm</th>
<th id="sd_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_flipper_length_mm</th>
<th id="var_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_flipper_length_mm</th>
<th id="length_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_flipper_length_mm</th>
<th id="q25_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_flipper_length_mm</th>
<th id="q75_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_flipper_length_mm</th>
<th id="iqr_flipper_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_flipper_length_mm</th>
<th id="mean_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_length_mm</th>
<th id="min_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_length_mm</th>
<th id="max_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_length_mm</th>
<th id="sd_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_length_mm</th>
<th id="var_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_length_mm</th>
<th id="length_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_length_mm</th>
<th id="q25_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_length_mm</th>
<th id="q75_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_length_mm</th>
<th id="iqr_bill_length_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_length_mm</th>
<th id="mean_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">mean_bill_depth_mm</th>
<th id="min_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">min_bill_depth_mm</th>
<th id="max_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">max_bill_depth_mm</th>
<th id="sd_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">sd_bill_depth_mm</th>
<th id="var_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">var_bill_depth_mm</th>
<th id="length_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">length_bill_depth_mm</th>
<th id="q25_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q25_bill_depth_mm</th>
<th id="q75_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">q75_bill_depth_mm</th>
<th id="iqr_bill_depth_mm" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">iqr_bill_depth_mm</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="species">Adelie</td>
<td class="gt_row gt_right" headers="n">152.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,700.66</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,850.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,775.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">458.57</td>
<td class="gt_row gt_right" headers="var_body_mass_g">210,282.89</td>
<td class="gt_row gt_right" headers="length_body_mass_g">152.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,350.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">4,000.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">650.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">189.95</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">172.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">210.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.54</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.76</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">186.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">195.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">38.79</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">32.10</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">46.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">2.66</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">7.09</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">36.75</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">40.75</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.00</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.35</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">15.50</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">21.50</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.22</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.48</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">152.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.00</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="species">Chinstrap</td>
<td class="gt_row gt_right" headers="n">68.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">3,733.09</td>
<td class="gt_row gt_right" headers="min_body_mass_g">2,700.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">4,800.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">384.34</td>
<td class="gt_row gt_right" headers="var_body_mass_g">147,713.45</td>
<td class="gt_row gt_right" headers="length_body_mass_g">68.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">3,487.50</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">462.50</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">195.82</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">178.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">7.13</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">50.86</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">191.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">201.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">10.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">48.83</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">58.00</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.34</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">11.15</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">46.35</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">51.08</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.73</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">18.42</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">16.40</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">20.80</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">1.14</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">1.29</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">68.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">17.50</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">19.40</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.90</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="species">Gentoo</td>
<td class="gt_row gt_right" headers="n">124.00</td>
<td class="gt_row gt_right" headers="mean_body_mass_g">5,076.02</td>
<td class="gt_row gt_right" headers="min_body_mass_g">3,950.00</td>
<td class="gt_row gt_right" headers="max_body_mass_g">6,300.00</td>
<td class="gt_row gt_right" headers="sd_body_mass_g">504.12</td>
<td class="gt_row gt_right" headers="var_body_mass_g">254,133.18</td>
<td class="gt_row gt_right" headers="length_body_mass_g">124.00</td>
<td class="gt_row gt_right" headers="q25_body_mass_g">4,700.00</td>
<td class="gt_row gt_right" headers="q75_body_mass_g">5,500.00</td>
<td class="gt_row gt_right" headers="iqr_body_mass_g">800.00</td>
<td class="gt_row gt_right" headers="mean_flipper_length_mm">217.19</td>
<td class="gt_row gt_right" headers="min_flipper_length_mm">203.00</td>
<td class="gt_row gt_right" headers="max_flipper_length_mm">231.00</td>
<td class="gt_row gt_right" headers="sd_flipper_length_mm">6.48</td>
<td class="gt_row gt_right" headers="var_flipper_length_mm">42.05</td>
<td class="gt_row gt_right" headers="length_flipper_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_flipper_length_mm">212.00</td>
<td class="gt_row gt_right" headers="q75_flipper_length_mm">221.00</td>
<td class="gt_row gt_right" headers="iqr_flipper_length_mm">9.00</td>
<td class="gt_row gt_right" headers="mean_bill_length_mm">47.50</td>
<td class="gt_row gt_right" headers="min_bill_length_mm">40.90</td>
<td class="gt_row gt_right" headers="max_bill_length_mm">59.60</td>
<td class="gt_row gt_right" headers="sd_bill_length_mm">3.08</td>
<td class="gt_row gt_right" headers="var_bill_length_mm">9.50</td>
<td class="gt_row gt_right" headers="length_bill_length_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_length_mm">45.30</td>
<td class="gt_row gt_right" headers="q75_bill_length_mm">49.55</td>
<td class="gt_row gt_right" headers="iqr_bill_length_mm">4.25</td>
<td class="gt_row gt_right" headers="mean_bill_depth_mm">14.98</td>
<td class="gt_row gt_right" headers="min_bill_depth_mm">13.10</td>
<td class="gt_row gt_right" headers="max_bill_depth_mm">17.30</td>
<td class="gt_row gt_right" headers="sd_bill_depth_mm">0.98</td>
<td class="gt_row gt_right" headers="var_bill_depth_mm">0.96</td>
<td class="gt_row gt_right" headers="length_bill_depth_mm">124.00</td>
<td class="gt_row gt_right" headers="q25_bill_depth_mm">14.20</td>
<td class="gt_row gt_right" headers="q75_bill_depth_mm">15.70</td>
<td class="gt_row gt_right" headers="iqr_bill_depth_mm">1.50</td>
</tr>
</tbody>
</table>

</div>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>using map: 0.043 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, using <code>map()</code> took approximately 14% longer than the explicit approach for this summary task. That result is not surprising. For simple grouped summaries, <code>map()</code> adds machinery that <code>dplyr</code> does not need. The value of this approach appears when the per-subset analysis becomes more substantial than a scalar summary table.</p>
</section>
<section id="why-bother-with-map" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="why-bother-with-map"><span class="header-section-number">9</span> Why bother with <code>map()</code>?</h2>
<p>The strongest case for <code>map()</code> is that it lets us abstract an analysis. We can write one function that knows how to analyze one input, test that function on a single subset, and then apply it to many inputs. This separation between the analysis logic and the iteration logic makes the workflow easier to test, debug, and reuse.</p>
<p>This abstraction matters when the output is more complex than a tibble of scalar summaries. Each subset might produce a model, a plot, a diagnostic table, a saved file, or a list of related outputs. Those outputs do not always fit neatly inside a single <code>summarize()</code> call, but they fit naturally into a <code>map()</code> workflow because <code>map()</code> can return lists or list-columns.</p>
<p>The same pattern also works well for file-based workflows. Instead of splitting one data frame into groups, we might start with a vector of file paths. Each file path can be mapped to a function that reads the file, analyzes it, and returns or saves the result. That pattern closely resembles how batch jobs and cluster workflows are often organized: one input, one analysis, one output.</p>
<p>Finally, <code>map()</code> prepares the code for parallel execution. Once the workflow is organized as “one input, one function, one result,” moving from <code>map()</code> to <code>furrr::future_map()</code> is a relatively small conceptual step. That makes <code>map()</code> a useful bridge from local sequential work to local multicore work.</p>
</section>
<section id="approach-6-parallel-split-apply-combine-with-future_map" class="level2" data-number="10">
<h2 data-number="10" class="anchored" data-anchor-id="approach-6-parallel-split-apply-combine-with-future_map"><span class="header-section-number">10</span> Approach 6: Parallel split-apply-combine with <code>future_map()</code></h2>
<p>The final approach uses the <code>future</code> and <code>furrr</code> packages to run the split-apply-combine workflow in parallel. The refactor is conceptually simple: define a function that summarizes one subset, split the data into subsets, and use <code>future_map_dfr()</code> to apply the function across those subsets.</p>
<p>Using multiple cores means allowing more than one R process to work at the same time. In a regular <code>map()</code> workflow, each subset is processed sequentially: R finishes the first subset, then moves to the second, then the third, and so on. In a <code>future_map()</code> workflow, those subset-level tasks can be distributed across multiple workers. A worker is an independent R session that can carry out one piece of the computation.</p>
<p>The number of workers should be chosen intentionally. More workers does not automatically mean faster code. Each worker has startup costs, memory costs, and communication costs. R may need to launch separate sessions, copy data and functions to those sessions, and collect the results when the jobs finish. If the individual jobs are small, that overhead can dominate the actual computation.</p>
<p>For this example, the unit of work is the species-level subset. Because the Palmer Penguins data have three species, we effectively have three independent jobs: one for Adelie, one for Chinstrap, and one for Gentoo. Using three workers matches the structure of the problem naturally. Each worker can take one species-level subset, run the same summary function, and return the result.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"using future apply"</span>)</span>
<span id="cb23-2"></span>
<span id="cb23-3">old_plan <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> future<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>()</span>
<span id="cb23-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on.exit</span>(future<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(old_plan), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb23-5"></span>
<span id="cb23-6">future<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(future<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>multisession, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb23-7"></span>
<span id="cb23-8">summary_funs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb23-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean   =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd     =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb23-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(x, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb23-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr    =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb23-18">)</span>
<span id="cb23-19"></span>
<span id="cb23-20">measure_vars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb23-21">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body_mass_g"</span>,</span>
<span id="cb23-22">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"flipper_length_mm"</span>,</span>
<span id="cb23-23">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_length_mm"</span>,</span>
<span id="cb23-24">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bill_depth_mm"</span></span>
<span id="cb23-25">)</span>
<span id="cb23-26"></span>
<span id="cb23-27">summarize_one_species <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb23-28">  species_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>species)</span>
<span id="cb23-29"></span>
<span id="cb23-30">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb23-32">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb23-33">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(</span>
<span id="cb23-34">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(measure_vars),</span>
<span id="cb23-35">        summary_funs,</span>
<span id="cb23-36">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.names =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{.fn}_{.col}"</span></span>
<span id="cb23-37">      ),</span>
<span id="cb23-38">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb23-39">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-40">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> species_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.before =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb23-41">}</span>
<span id="cb23-42"></span>
<span id="cb23-43">p_stats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_split</span>(species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb23-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">future_map_dfr</span>(</span>
<span id="cb23-46">    summarize_one_species,</span>
<span id="cb23-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">furrr_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb23-48">  )</span>
<span id="cb23-49"></span>
<span id="cb23-50"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>using future apply: 4.187 sec elapsed</code></pre>
</div>
</div>
<p>On my machine, using three workers took approximately 6.4 seconds. By contrast, using nine workers did not make the job faster. In fact, the same task took approximately 9.468 seconds with nine workers. That result is a useful reminder that parallel execution is not just about using as many cores as possible. The number of workers should reflect the number of independent tasks, the size of those tasks, and the overhead required to coordinate them.</p>
<p>For this exact summary task, the data are small enough and the per-species calculations are short enough that parallelization is not necessarily faster than the non-parallel approaches. The pattern is still useful because it is the same pattern you would use for larger workflows that train models, run simulations, process many files, or execute longer analyses independently across data chunks.</p>
<p>When moving from <code>map()</code> to <code>future_map()</code>, the line-level change is small, but the surrounding execution environment matters. You need a future plan, a deliberate number of workers, a strategy for random-number generation if the analysis uses randomness, and enough care to avoid moving unnecessarily large objects to each worker. In this example, <code>furrr_options(seed = TRUE)</code> is included to make random-number generation parallel-safe if randomness is introduced later.</p>
</section>
<section id="timing-summary" class="level2" data-number="11">
<h2 data-number="11" class="anchored" data-anchor-id="timing-summary"><span class="header-section-number">11</span> Timing summary</h2>
<p>The table below collects the wall-clock times for each approach on the same dataset. These numbers are illustrative and machine-specific. All measurements were taken on a 2024 MacBook Pro with an M4 chip, 48GB of memory, running macOS Tahoe 26.5. Your results will differ, but the relative ordering is likely to be informative regardless of hardware.</p>
<div class="cell">
<div class="cell-output-display">
<div id="nujisvlzej" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#nujisvlzej table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#nujisvlzej thead, #nujisvlzej tbody, #nujisvlzej tfoot, #nujisvlzej tr, #nujisvlzej td, #nujisvlzej th {
  border-style: none;
}

#nujisvlzej p {
  margin: 0;
  padding: 0;
}

#nujisvlzej .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#nujisvlzej .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#nujisvlzej .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#nujisvlzej .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#nujisvlzej .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#nujisvlzej .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#nujisvlzej .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#nujisvlzej .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#nujisvlzej .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#nujisvlzej .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#nujisvlzej .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#nujisvlzej .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#nujisvlzej .gt_spanner_row {
  border-bottom-style: hidden;
}

#nujisvlzej .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#nujisvlzej .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#nujisvlzej .gt_from_md > :first-child {
  margin-top: 0;
}

#nujisvlzej .gt_from_md > :last-child {
  margin-bottom: 0;
}

#nujisvlzej .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#nujisvlzej .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#nujisvlzej .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#nujisvlzej .gt_row_group_first td {
  border-top-width: 2px;
}

#nujisvlzej .gt_row_group_first th {
  border-top-width: 2px;
}

#nujisvlzej .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#nujisvlzej .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#nujisvlzej .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#nujisvlzej .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#nujisvlzej .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#nujisvlzej .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#nujisvlzej .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#nujisvlzej .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#nujisvlzej .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#nujisvlzej .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#nujisvlzej .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#nujisvlzej .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#nujisvlzej .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#nujisvlzej .gt_left {
  text-align: left;
}

#nujisvlzej .gt_center {
  text-align: center;
}

#nujisvlzej .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#nujisvlzej .gt_font_normal {
  font-weight: normal;
}

#nujisvlzej .gt_font_bold {
  font-weight: bold;
}

#nujisvlzej .gt_font_italic {
  font-style: italic;
}

#nujisvlzej .gt_super {
  font-size: 65%;
}

#nujisvlzej .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#nujisvlzej .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#nujisvlzej .gt_indent_1 {
  text-indent: 5px;
}

#nujisvlzej .gt_indent_2 {
  text-indent: 10px;
}

#nujisvlzej .gt_indent_3 {
  text-indent: 15px;
}

#nujisvlzej .gt_indent_4 {
  text-indent: 20px;
}

#nujisvlzej .gt_indent_5 {
  text-indent: 25px;
}

#nujisvlzej .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#nujisvlzej div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<thead>
<tr class="gt_col_headings header">
<th id="Approach" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">Approach</th>
<th id="Time_s" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col">Time (s)<span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span></th>
<th id="Delta_s" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col"><strong>±</strong> vs Approach 1 (s)</th>
<th id="Delta_pct" class="gt_col_heading gt_columns_bottom_border gt_right" data-quarto-table-cell-role="th" scope="col"><strong>±</strong> vs Approach 1 (%)</th>
<th id="Best_for" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col">Best suited for</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="Approach">1: Explicit summaries</td>
<td class="gt_row gt_right" headers="Time_s">2.019</td>
<td class="gt_row gt_right" headers="Delta_s">0.000</td>
<td class="gt_row gt_right" headers="Delta_pct">0.00</td>
<td class="gt_row gt_left" headers="Best_for">Teaching and one-off analyses where every calculation should be visible and nothing is hidden behind abstraction. Easy to read, hard to maintain at scale.</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="Approach">2: For loops</td>
<td class="gt_row gt_right" headers="Time_s">2.362</td>
<td class="gt_row gt_right" headers="Delta_s" style="color: #9B0000">0.343</td>
<td class="gt_row gt_right" headers="Delta_pct">17.00</td>
<td class="gt_row gt_left" headers="Best_for">Demonstrating what grouped summaries are doing under the hood. Useful for building intuition about iteration, less useful for production code.</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="Approach">3: Declarative summaries with across()</td>
<td class="gt_row gt_right" headers="Time_s">2.059</td>
<td class="gt_row gt_right" headers="Delta_s" style="color: #9B0000">0.040</td>
<td class="gt_row gt_right" headers="Delta_pct">1.98</td>
<td class="gt_row gt_left" headers="Best_for">The recommended default for grouped scalar summaries. Compact, maintainable, and idiomatic. Adding or removing a statistic requires editing a list, not rewriting a block.</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="Approach">4: Per-group workflows with group_modify()</td>
<td class="gt_row gt_right" headers="Time_s">2.262</td>
<td class="gt_row gt_right" headers="Delta_s" style="color: #9B0000">0.243</td>
<td class="gt_row gt_right" headers="Delta_pct">12.03</td>
<td class="gt_row gt_left" headers="Best_for">Cases where each group needs a custom mini-pipeline that returns a data frame more complex than a row of scalar summaries.</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="Approach">5: Split-apply-combine with map()</td>
<td class="gt_row gt_right" headers="Time_s">2.300</td>
<td class="gt_row gt_right" headers="Delta_s" style="color: #9B0000">0.281</td>
<td class="gt_row gt_right" headers="Delta_pct">13.92</td>
<td class="gt_row gt_left" headers="Best_for">Workflows where each subset is an independent unit of analysis, especially when the output may be a model, a plot, a file, or a list rather than a flat tibble.</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="Approach">6: Parallel execution with future_map()</td>
<td class="gt_row gt_right" headers="Time_s">6.400</td>
<td class="gt_row gt_right" headers="Delta_s" style="color: #9B0000">4.381</td>
<td class="gt_row gt_right" headers="Delta_pct">217.00</td>
<td class="gt_row gt_left" headers="Best_for">Large-scale workflows with many independent inputs: many files, many simulations, many model fits. Overhead dominates for small tasks like this one.</td>
</tr>
</tbody><tfoot>
<tr class="gt_footnotes odd">
<td colspan="5" class="gt_footnote"><span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span> Measured on a 2024 MacBook Pro, M4 chip, 48GB RAM, macOS Tahoe 26.5. The future_map() time reflects 3-worker multisession overhead on a small dataset; for larger workloads the relationship inverts.</td>
</tr>
</tfoot>

</table>

</div>
</div>
</div>
<p>The clearest takeaway from the timing data is that for this particular task — scalar grouped summaries on a moderately sized dataset — the differences among Approaches 1 through 4 are small enough to be practically irrelevant. The choice among them should be driven by readability and maintainability, not speed. The <code>map()</code> and <code>future_map()</code> approaches carry overhead that only pays off when the per-subset work is substantial enough to justify the cost of splitting, distributing, and collecting results.</p>
</section>
<section id="recommended-approach-knowing-when-to-reach-for-which-tool" class="level2" data-number="12">
<h2 data-number="12" class="anchored" data-anchor-id="recommended-approach-knowing-when-to-reach-for-which-tool"><span class="header-section-number">12</span> Recommended approach: knowing when to reach for which tool</h2>
<p>The six approaches in this post converge on the same result, but they reflect meaningfully different assumptions about the shape of the problem. Before closing, it is worth being explicit about the decision point that separates them.</p>
<p><code>across()</code> inside a <code>summarize()</code> call is the right tool when the goal is a flat tibble with one row per group and scalar values in every cell. This is the case for most descriptive summary tables: means, standard deviations, quantiles, counts. <code>dplyr</code> is optimized for exactly this pattern, and <code>across()</code> expresses it concisely. The return object is predictable — a tibble with a fixed shape that is easy to print, save, or pass downstream.</p>
<p><code>map()</code> and <code>future_map()</code> are the right tools when that assumption breaks down. If each subset needs to return something other than a row of scalars — a fitted model, a diagnostic plot, a list of outputs, a saved file — then <code>summarize()</code> is no longer the right container, and <code>map()</code> steps in. The return object from a <code>map()</code> call is a list, which can hold anything: tibbles of different shapes, model objects, ggplot objects, or nested structures. That generality is precisely what makes <code>map()</code> more powerful and also slightly heavier than <code>across()</code>.</p>
<p>In other words, the decision point is the shape of the output. If each group produces one row, reach for <code>across()</code>. If each group produces something else — or something you are not sure about yet — reach for <code>map()</code>. And if those per-group tasks are large enough and independent enough that running them sequentially feels wasteful, reach for <code>future_map()</code> and let your laptop’s cores share the load.</p>


</section>

 ]]></description>
  <category>data-science</category>
  <category>r</category>
  <guid>https://erwinlares.com/posts/2026-06-05-split-apply-combine/</guid>
  <pubDate>Mon, 11 May 2026 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
