-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d24497
commit 4b0decc
Showing
11 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_extensions | ||
|
||
*_files/libs | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Function to calculate bread weight | ||
get_bread_weight <- function(flour_weight, hydration = 0.7, water_loss = 0.1) { | ||
|
||
water_weight <- hydration * flour_weight | ||
bread_weight <- (1 - water_loss) * (flour_weight + water_weight) | ||
cat("Bread weight:", bread_weight, "kg", "\n") | ||
|
||
return(bread_weight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# An example script that defines a bread recipe | ||
|
||
flour_weight <- 1.0 | ||
water_weight <- 0.7 * flour_weight | ||
bread_weight <- 0.9 * (flour_weight + water_weight) | ||
cat("Bread weight:", bread_weight, "kg", "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# multiply two numbers, and say hello [documentation] | ||
multiply <- function(a, b) { # [header]: [name] <- function([arguments]) | ||
|
||
# [body] | ||
answer <- a * b | ||
print("hello") # [side effects] | ||
|
||
return(answer) # [return value] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Calls R/parametric_script.R with different parameters | ||
|
||
rm(list = ls()) # clear the workspace | ||
|
||
# loads get_bread_weight function | ||
source("R/bread_function.R") | ||
|
||
bread_weight_1 <- get_bread_weight(flour_weight = 1.0, hydration = 0.7) | ||
bread_weight_2 <- get_bread_weight(flour_weight = 2.0, hydration = 0.8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Parametric bread recipe script. | ||
# Requires: flour_weight, hydration, water_loss | ||
|
||
water_weight <- hydration * flour_weight | ||
bread_weight <- (1 - water_loss) * (flour_weight + water_weight) | ||
cat("Bread weight:", bread_weight, "kg", "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Calls R/parametric_script.R with different parameters | ||
|
||
rm(list = ls()) # clear the workspace | ||
|
||
flour_weight <- 1.0 | ||
hydration <- 0.7 | ||
water_loss <- 0.1 | ||
|
||
source("R/parametric_script.R") | ||
bread_weight_1 <- bread_weight | ||
|
||
flour_weight <- 2.0 | ||
hydration <- 0.8 | ||
|
||
source("R/parametric_script.R") | ||
bread_weight_2 <- bread_weight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# How NOT to write variations of the same code | ||
|
||
flour_weight <- 1.0 | ||
water_weight <- 0.7 * flour_weight | ||
bread_weight <- 0.9 * (flour_weight + water_weight) | ||
cat("Bread weight:", bread_weight, "kg", "\n") | ||
|
||
flour_weight_2 <- 2.0 | ||
water_weight_2 <- 0.8 * flour_weight_2 | ||
bread_weight_2 <- 0.9 * (flour_weight_2 + water_weight_2) | ||
cat("Bread weight:", bread_weight_2, "kg", "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
|
||
## Rendering | ||
|
||
1. Install [R](https://www.r-project.org/) and [Quarto](https://quarto.org/docs/get-started/). | ||
|
||
1. Install the [include-code-files](https://github.com/quarto-ext/include-code-files) extension: | ||
|
||
```.sh | ||
quarto add quarto-ext/include-code-files | ||
``` | ||
|
||
1. Render the slides: | ||
|
||
```.sh | ||
quarto render functions.qmd | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*-- scss:defaults --*/ | ||
$presentation-font-size-root: 28px; | ||
$presentation-h2-font-size: 1.4em; | ||
$code-block-font-size: 0.8em; | ||
|
||
/*-- scss:rules --*/ | ||
.reveal li { | ||
margin-top: 0 !important; | ||
margin-bottom: 0 !important; | ||
} | ||
|
||
.reveal h4 { | ||
margin: 0.8em 0 0.2em 0; | ||
} | ||
|
||
div.code-with-filename { | ||
margin: 1em 0 1em 0; | ||
} | ||
|
||
div.cell-output { | ||
margin: 0 0 1em 0; | ||
} |
Oops, something went wrong.