Skip to content

Commit 0f51dc9

Browse files
committed
rearrange list of steps in iteration
1 parent 8ffbbb4 commit 0f51dc9

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

episodes/superspreading-simulate.Rmd

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,28 +456,28 @@ First, let's sketch how we use `purrr::map()` with `epichains::simulate_chains()
456456
- `.x`, with a vector of numbers, and
457457
- `.f`, a function to iterate to each vector value.
458458

459+
The code chunk below
460+
459461
```r
460-
map(
461-
# vector of numbers (simulation IDs)
462-
.x = seq_len(number_simulations),
463-
# function to iterate to each simulation ID number
464-
.f = function(sim) {
465-
simulate_chains(...) %>%
466-
# creates a column with the simulation ID number
467-
mutate(simulation_id = sim)
468-
}
469-
) %>%
470-
# combine list outputs (for each simulation ID) into a single data frame
471-
list_rbind()
462+
# steps:
463+
# seq_len() creates a vector with sequence of numbers (simulation IDs from 1 to 1000) and
464+
# function(sim) iterates {epichains} to each simulation ID number, then
465+
# dplyr::mutate() adds a column to the <epichains> output with the simulation ID number.
466+
# purrr::list_rbind() combines all the list class outputs (for each simulation ID) into a single data frame.
467+
purrr::map(.x = seq_len(number_simulations), .f = function(sim) {
468+
epichains::simulate_chains(...) %>% dplyr::mutate(simulation_id = sim)
469+
}) %>%
470+
purrr::list_rbind()
471+
# pseudo code: do not run.
472472
```
473473

474474
The `sim` element is placed to register the iteration number (**simulation ID**) as a new column in the `<epichains>` output. The `purrr::list_rbind()` function aims to combine all the list outputs from `map()`.
475475

476-
**Why a dot (`.`) as a prefix?** In the [tidy design principles](https://design.tidyverse.org/dots-prefix.html) book we have a chapter on the dot prefix!
476+
**Why a dot (`.`) as a prefix before x and f arguments?** In the [tidy design principles](https://design.tidyverse.org/dots-prefix.html) book we have a chapter on the dot prefix!
477477

478478
:::::::::::::::::::::::::::::::
479479

480-
Now, we are prepared to use `map()` to repeatedly simulate from `simulate_chains()` and store in a vector from 1 to `r number_simulations`:
480+
Now, we are prepared to use `purrr::map()` to repeatedly simulate from `simulate_chains()` and store in a vector from 1 to `r number_simulations`:
481481

482482
```{r}
483483
set.seed(33)

0 commit comments

Comments
 (0)