Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martinherrerias committed Nov 27, 2024
1 parent 0d24497 commit 4b0decc
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_extensions

*_files/libs
*.html
9 changes: 9 additions & 0 deletions R/bread_function.R
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)
}
6 changes: 6 additions & 0 deletions R/bread_script.R
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")
9 changes: 9 additions & 0 deletions R/function_syntax.R
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]
}
9 changes: 9 additions & 0 deletions R/main.R
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)
6 changes: 6 additions & 0 deletions R/parametric_script.R
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")
16 changes: 16 additions & 0 deletions R/still_bad.R
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
11 changes: 11 additions & 0 deletions R/worst_idea.R
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")
17 changes: 17 additions & 0 deletions README.md
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
```
22 changes: 22 additions & 0 deletions custom.scss
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;
}
Loading

0 comments on commit 4b0decc

Please sign in to comment.