Skip to content

Commit cc38ae6

Browse files
committed
FIx headers
1 parent 19b42a7 commit cc38ae6

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

docs/education.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ <h1 class="title">Education</h1>
393393

394394
<div class="quarto-listing quarto-listing-container-default" id="listing-listing">
395395
<div class="list quarto-listing-default">
396-
<div class="quarto-post image-right" data-index="0" data-categories="YWNhZGVtaWElMkNSJTJDcHJvZ3JhbW1pbmc=" data-listing-date-sort="1756044000000" data-listing-file-modified-sort="1756097116155" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="13" data-listing-word-count-sort="2533">
396+
<div class="quarto-post image-right" data-index="0" data-categories="YWNhZGVtaWElMkNSJTJDcHJvZ3JhbW1pbmc=" data-listing-date-sort="1756044000000" data-listing-file-modified-sort="1756117307171" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="13" data-listing-word-count-sort="2522">
397397
<div class="thumbnail"><a href="./education/2025-08-25-WritingFunctions/index.html" class="no-external">
398398

399399
<img loading="lazy" src="./education/2025-08-25-WritingFunctions/workshop-image.svg" class="thumbnail-image">

docs/education/2025-08-25-WritingFunctions/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ <h1 class="title">Writing Flexible Functions in R</h1>
407407
</ul></nav>
408408
</div>
409409
<!-- main -->
410-
<main class="content quarto-banner-title-block column-page-left" id="quarto-document-content"><p>For this session we are going to use the <a href="https://www.gapminder.org/"><code>gapminder</code></a> dataset.</p>
410+
<main class="content quarto-banner-title-block column-page-left" id="quarto-document-content"><section id="why-we-use-functions-in-r" class="level1" data-number="1"><h1 data-number="1">
411+
<span class="header-section-number">1</span> Why We Use Functions in R</h1>
412+
<p>For this session we are going to use the <a href="https://www.gapminder.org/"><code>gapminder</code></a> dataset.</p>
411413
<div class="callout callout-style-default callout-note callout-titled">
412414
<div class="callout-header d-flex align-content-center">
413415
<div class="callout-icon-container">
@@ -427,8 +429,6 @@ <h1 class="title">Writing Flexible Functions in R</h1>
427429
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://tidyverse.tidyverse.org">tidyverse</a></span><span class="op">)</span></span>
428430
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/jennybc/gapminder">gapminder</a></span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
429431
</div>
430-
<section id="why-we-use-functions-in-r" class="level1" data-number="1"><h1 data-number="1">
431-
<span class="header-section-number">1</span> Why We Use Functions in R</h1>
432432
<p>Functions are the building blocks of reproducible analysis in R. They:</p>
433433
<ul>
434434
<li>Help you avoid repeating yourself (DRY principle)</li>
@@ -1092,8 +1092,6 @@ <h1 class="title">Writing Flexible Functions in R</h1>
10921092
<code>@return</code>: Describes what the function returns</li>
10931093
<li>
10941094
<code>@examples</code>: Shows how to use the function</li>
1095-
<li>
1096-
<code>@export</code>: Makes the function available when building a package</li>
10971095
</ul>
10981096
<p>Let’s document one of our curly-curly functions as well:</p>
10991097
<div class="cell">

docs/search.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"href": "education/2025-08-25-WritingFunctions/index.html",
4040
"title": "Writing Flexible Functions in R",
4141
"section": "",
42-
"text": "For this session we are going to use the gapminder dataset.\nBefore we start, let’s load the packages we’ll need:\nlibrary(tidyverse)\nlibrary(gapminder)"
42+
"text": "For this session we are going to use the gapminder dataset.\n\n\n\n\n\n\nAbout the Gapminder Dataset\n\n\n\nThe gapminder dataset contains information about life expectancy, population, and GDP per capita for countries around the world from 1952 to 2007. This dataset was made famous by Hans Rosling, a Swedish physician and statistician who used it in his captivating TED talks to challenge misconceptions about global development. Rosling’s animated visualisations of this data revealed surprising trends about how countries have progressed over time, showing that the world has become healthier and wealthier than many people realise.\nThe dataset is perfect for demonstrating data analysis techniques because it contains both categorical variables (country, continent) and numerical variables (year, life expectancy, population, GDP per capita), with enough complexity to showcase real-world data challenges while remaining manageable for learning purposes.\n\n\nBefore we start, let’s load the packages we’ll need:\n\nlibrary(tidyverse)\nlibrary(gapminder)\n\nFunctions are the building blocks of reproducible analysis in R. They:\n\nHelp you avoid repeating yourself (DRY principle)\nMake your code easier to read, test, and debug\nAllow you to generalise analyses to any dataset\nEnable collaboration and sharing of code\n\nToday, we’ll learn how to write flexible functions that work with any data, and how to document them for others to use."
4343
},
4444
{
4545
"objectID": "education/2025-08-25-WritingFunctions/index.html#the-problem-functions-dont-work-with-dplyr",
@@ -81,7 +81,7 @@
8181
"href": "education/2025-08-25-WritingFunctions/index.html#common-roxygen2-tags",
8282
"title": "Writing Flexible Functions in R",
8383
"section": "\n10.1 Common roxygen2 Tags",
84-
"text": "10.1 Common roxygen2 Tags\n\n\n@param: Describes each parameter\n\n@return: Describes what the function returns\n\n@examples: Shows how to use the function\n\n@export: Makes the function available when building a package\n\nLet’s document one of our curly-curly functions as well:\n\n#' Create a summary by group\n#'\n#' This function groups data by a specified column and calculates the mean\n#' and count for another column.\n#'\n#' @param data A data frame\n#' @param group_column Column to group by (unquoted)\n#' @param summary_column Column to summarise (unquoted)\n#' @return A data frame with group, average, and count columns\n#' @examples\n#' my_summary(gapminder, continent, lifeExp)\n#' my_summary(gapminder, year, gdpPercap)\nmy_summary &lt;- function(data, group_column, summary_column) {\n data %&gt;%\n group_by({{group_column}}) %&gt;%\n summarise(\n average = mean({{summary_column}}, na.rm = TRUE),\n count = n(),\n .groups = \"drop\"\n )\n}\n\n\n\n\n\n\n\nBuilding Packages\n\n\n\nIf you’re building an R package, you can use devtools::document() to automatically generate help files from your roxygen2 comments. This creates the standard R help documentation that users can access with ?function_name."
84+
"text": "10.1 Common roxygen2 Tags\n\n\n@param: Describes each parameter\n\n@return: Describes what the function returns\n\n@examples: Shows how to use the function\n\nLet’s document one of our curly-curly functions as well:\n\n#' Create a summary by group\n#'\n#' This function groups data by a specified column and calculates the mean\n#' and count for another column.\n#'\n#' @param data A data frame\n#' @param group_column Column to group by (unquoted)\n#' @param summary_column Column to summarise (unquoted)\n#' @return A data frame with group, average, and count columns\n#' @examples\n#' my_summary(gapminder, continent, lifeExp)\n#' my_summary(gapminder, year, gdpPercap)\nmy_summary &lt;- function(data, group_column, summary_column) {\n data %&gt;%\n group_by({{group_column}}) %&gt;%\n summarise(\n average = mean({{summary_column}}, na.rm = TRUE),\n count = n(),\n .groups = \"drop\"\n )\n}\n\n\n\n\n\n\n\nBuilding Packages\n\n\n\nIf you’re building an R package, you can use devtools::document() to automatically generate help files from your roxygen2 comments. This creates the standard R help documentation that users can access with ?function_name."
8585
},
8686
{
8787
"objectID": "education/2025-08-25-WritingFunctions/index.html#key-takeaways",

education/2025-08-25-WritingFunctions/index.qmd

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ editor:
1919
wrap: sentence
2020
---
2121

22+
# Why We Use Functions in R
23+
2224
For this session we are going to use the [`gapminder`](https://www.gapminder.org/) dataset.
2325

2426
::: {.callout-note}
@@ -40,7 +42,6 @@ library(tidyverse)
4042
library(gapminder)
4143
```
4244

43-
# Why We Use Functions in R
4445
Functions are the building blocks of reproducible analysis in R. They:
4546

4647
- Help you avoid repeating yourself (DRY principle)
@@ -125,6 +126,7 @@ Try changing the threshold in `filter_lifeExp()` to see how the plot changes.
125126

126127

127128
:::{.callout-important}
129+
128130
## The Limitation of Fixed Column Names
129131

130132
But what if we wanted more flexible functions that can take many different column names? Or even work with a completely different dataset with different column names?
@@ -202,10 +204,6 @@ gg <- gapminder %>%
202204
203205
```
204206

205-
206-
207-
208-
209207
:::{.callout-tip}
210208
## The `[[]]` approach works, but...
211209

@@ -454,9 +452,6 @@ Use `...` when you want to:
454452
**Be careful**: `...` can make debugging harder since you don't know what arguments might be passed!
455453
:::
456454

457-
458-
459-
460455
# Documenting Your Functions
461456

462457
Documenting your functions is essential for sharing and future use. Good documentation helps others (and future you!) understand:
@@ -504,7 +499,6 @@ filter_gapminder <- function(data, column_name, threshold) {
504499
- `@param`: Describes each parameter
505500
- `@return`: Describes what the function returns
506501
- `@examples`: Shows how to use the function
507-
- `@export`: Makes the function available when building a package
508502

509503
Let's document one of our curly-curly functions as well:
510504

@@ -567,8 +561,3 @@ Try creating your own functions that:
567561

568562
Remember: the best functions are flexible, well-documented, and solve real problems in your analysis workflow!
569563

570-
571-
572-
573-
574-

0 commit comments

Comments
 (0)