class: center, middle, inverse, title-slide # Automatized files management ## 15’ class for the R-Studio Certification ### Florencia D’Andrea ### 🐦cantoflor_87 --- class: center, middle # Iteration with purrr package ### for automatized files management ### 📄🐱 --- class: inverse, center, middle ### 1. Obtain a dataframe from multiple files ### 2. Automatize report generation --- class: inverse, center, middle ### 👉<span style="color: #f2cc9d;">1. Obtain a dataframe from multiple files</span> ### 2. Automatize report generation --- ### Read files using `map_df()` <img src="1_eng.png" width="1809" /> --- ### Read files using `map_df()` <img src="2_eng.png" width="1805" /> --- ### Return value: a dataframe <img src="3_eng.png" width="1805" /> --- # Let’s practise 💪 ### Which function would you use to obtain these return values? 1. `map()` 2. `map_df()` 3. `map_chr()` <img src="4_eng.png" width="1743" /> --- class: inverse, center, middle # Live coding #1 💻 #### 1. Build a vector of `filenames` you want to iterate over #### 2. Select a `function` to read the files #### 3. Check the number of `arguments` the function needs #### 4. Select among `map()`/`map2()`/`pmap()` #### 5. Select a `map_*()` suffix in relation to the *desired output* File `live_coding.R` in [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/flor14/purrr_class/master?urlpath=rstudio) --- class: inverse, center, middle ### 1. Obtain a dataframe from multiple files ### 2. Automatize report generation --- class: inverse, center, middle ### 1. Obtain a dataframe from multiple files ### 👉 <span style="color: #f2cc9d;">2. Automatize report generation</span> --- ### Iterate using a function for its side effects <img src="5_eng.png" width="1636" /> --- ### `purrr::walk()` family of functions <img src="6_eng.png" width="500" /> --- # Let´s practise 💪 ### Which of these functions you would use with walk() family of functions? 1. `purrr::safely()` 2. `~ggplot(., aes(mpg, wt)) + geom_point()` 3. `rmarkdown::render()` 4. `~list(name = .)` Can you explain your choice on using `map()` or `walk()` to iterate with these functions? --- ### RMarkdown 🧶 <img src="rmd.png" width="700" /> --- ### RMarkdown Template file Add parameters <img src="yaml.png" width="979" /> --- ### Automatization of report generation <img src="7_eng.png" width="1596" /> --- ### `pwalk()` function 🧶😺 <img src="final_scheme.png" width="1764" /> --- class: inverse, center, middle # Live coding #2 💻 Get your own series of reports! File `live_coding.R` in [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/flor14/purrr_class/master?urlpath=rstudio) --- class: center, middle # Thanks! ### 😺🧶😺🧶😺🧶 Slides created via the R package [**xaringan**](https://github.com/yihui/xaringan).