class: inverse, center, middle # .big[.teal[FORKS]] # .bigger[in the road] <style> code {font-size: 1.8rem !important; line-height: 1.2 !important;} blockquote {font-size: 1.8rem !important; line-height: 1.2 !important;} .bump-up {margin-top: -30px} </style> --- class: inverse, middle, center # .bigger[.blue[if_else( )]] --- class: inverse exclude: true # How to survive <br> <code> ## if_else(.teal[scary], .teal["TURN BACK NOW!"], ## .gray["KEEP GOING."]) </code> --- class: <div style="width: 137%; margin-left: -140px; margin-top: -70px;"> <label class="clicktogif" title="click to play"> <input type="checkbox"> <img src="https://github.com/tidy-MN/R-camp-slides/blob/main/slides/images/scary_forest2.gif?raw=true"> </label> </div> --- class: exclude: true <div style="width: 137%; margin-left: -140px; margin-top: -70px;"> <img src="../images/scary_forest.gif"> </div> --- class: exclude: true <div style="width: 137%; margin-left: -140px; margin-top: -70px;"> <img src="../images/how_2_survive2.gif"> </div> --- class: inverse # How to survive <img style="margin-top: -74px; margin-left: -13.2%; width: 122%; max-width: 122%;" src="../images/ifelse_scary_big.svg" alt="An if_else() statement that reads: if else: path is scary, then 'Turn back!', else 'Keep going.'"> --- class: exclude: true # How to survive <img src="../images/if_else_scary.svg" alt="An if_else() statement that reads: if else: scary, then 'Turn back now!', else 'Keep going.'"> .small[.darkgray[.bottom-right[ **NOTE:** Also listen to the worm if you are in a Labyrinth. ]]] --- # Monster bakers <img src="../images/monsters/monster_data.png" style="width: 73%; margin-top: -10px; margin-left: 12px;"> --- class: center, middle <div style="height: 120px; overflow:hidden;"> <img src="../images/monsters/ifelse_baker1.png" style="width: 155%; max-width: 155%;"> </div> --- class: center, middle <div style="height: 128px; overflow:hidden; margin-top: 30px;"> <img src="../images/monsters/ifelse_baker3.png" style="width: 155%; max-width: 155%; margin-top: -70px; margin-left: -222px;"> </div> --- class: center, middle <div style="height: 170px; overflow:hidden;"> <img src="../images/monsters/ifelse_baker3.png" style="width: 130%; max-width: 155%; margin-left: -30px;"> </div> --- <div style="height: 108px; overflow:hidden;"> <img src="../images/monsters/ifelse_baker3.png" style="width: 120%; max-width: 122%; margin-top: 4px;"> </div> <div style="margin-top: 81px; overflow:hidden; "> <img src="../images/monsters/ifelse_baker_slide2.png" style="width: 83%; margin-top: 0; margin-left: 31px;"> </div> --- class: center, middle <div style="height: 120px; overflow: hidden; margin-top: 10px; margin-left: -24px;"> <img src="../images/monsters/ifelse_baby0.png" style="width: 155%; max-width: 155%;"> </div> <img src="../images/monsters/baby_monster.png" style="width: 116px; margin-top: -5px; margin-left: -12px; max-width: 150%;"> --- class: center, middle <div style="height: 113px; margin-top: 17px; margin-left: -105px; width: 103%;"> <img src="../images/monsters/ifelse_baby05.png" style="width: 135%; max-width: 155%;"> </div> <img src="../images/monsters/baby_monster.png" style="width: 116px; margin-top: -5px; margin-left: -12px; max-width: 150%;"> --- <div> <img src="../images/monsters/ifelse_baby1.png" style="width: 108%; max-width: 108%; margin-top: 4px;"> </div> <div style="overflow:hidden; width: 65.3%;"> <div style="margin-top: 24px; overflow:hidden; width: 619px;"> <img src="../images/monsters/ifelse_baby2.png" style="width: 118.6%; margin-top: 8px; margin-left: 24px; max-width: 150%;"> </div></div> --- <div> <img src="../images/monsters/ifelse_baby1.png" style="width: 108%; max-width: 108%; margin-top: 4px;"> </div> <div style="margin-top: 24px; overflow:hidden; "> <img src="../images/monsters/ifelse_baby2.png" style="width: 78%; margin-top: 8px; margin-left: 24px;"> </div> --- class: inverse, middle, center # .bigger[.blue[case_when( )]] --- # What to wear? -- <br><br> ```r case_when( run_from_monsters ~ "Sneakers" ) ``` --- # What to wear? <br><br> ```r case_when( run_from_monsters ~ "Sneakers", swim_from_monsters ~ "Flippers" ) ``` --- # What to wear? <br><br> ```r case_when( run_from_monsters ~ "Sneakers", swim_from_monsters ~ "Flippers", TRUE ~ "Slippers" ) ``` --- # What to wear? <br><br> <style> #wide {width: 100%;} </style> ```r footwear = case_when( run_from_monsters ~ "Sneakers", swim_from_monsters ~ "Flippers", TRUE ~ "Slippers" ) ``` </div> --- class: center, middle <div style="height: 120px; overflow: hidden; margin-top: 0px; margin-left: -50px;"> <img src="../images/monsters/ifelse_baby0.png" style="width: 155%; max-width: 165%;"> </div> --- class: center, middle <div style="overflow: hidden; margin-top: 0px; margin-left: -20px; width: 110%;"> <img src="../images/monsters/case_when0.png" style="width: 155%; max-width: 155%;"> </div> --- class: center, middle exclude: true <div style="overflow: hidden; margin-top: 0px; margin-left: -90px; width: 110%;"> <img src="../images/monsters/case_when1.png" style="width: 149%; max-width: 155%;"> </div> --- class: center, middle <div style="overflow: hidden; margin-top: 57px; width: 114%;"> <img src="../images/monsters/case_when2.png" style="width: 149.1%; max-width: 155%; margin-left: -315px;"> </div> --- class: center, middle <div style="overflow: hidden; margin-top: 57px; width: 114%;"> <img src="../images/monsters/case_when3.png" style="width: 149.1%; max-width: 155%; margin-left: -315px;"> </div> --- class: center, middle <div style="overflow: hidden; margin-top: 57px; width: 114%; margin-left: -80px;"> <img src="../images/monsters/case_when3.png" style="width: 152%; max-width: 155%;"> </div> --- class: center, middle <div style="overflow: hidden; margin-top: 10px; margin-left: -90px; width: 114%;"> <img src="../images/monsters/case_when4.png" style="width: 138%; max-width: 155%;"> </div> --- <div style="height: 200px; overflow: hidden; margin-top: 10px; margin-left: -24px;"> <img src="../images/monsters/case_when4.png" style="width: 131%; max-width: 155%;"> </div> <div style="margin-top: 20px; overflow:hidden;"> <img src="../images/monsters/case_when_slide.png" style="width: 80%;"> </div> --- class: inverse, middle, center exclude: true # .bigger[.big[.teal[%>%]]] # .bigger[the pipe] --- class: inverse, center, middle <img src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/PNG/pipe.png" style="width: 32%; margin-top: 0;"> # .bigger[the pipe] --- class: center, middle, inverse # .bigger[.big[.teal[%>%]]] <br> # .bigger["and then..."] --- # Patty cake ```r patty_cake %>% ``` --- # Patty cake ```r patty_cake %>% * roll_it() %>% ``` --- # Patty cake ```r patty_cake %>% roll_it() %>% * prick_it() %>% ``` --- # Patty cake ```r patty_cake %>% roll_it() %>% prick_it() %>% * mark_it(letter = "B") ``` -- .bigger[ **Read as:** ] .bump-up[ > Take a **patty cake** (and then) > roll it (and then) > prick it (and then) > mark it - with the letter "B". ] --- exclude: true # There is a puppy ```r puppy %>% runs_outside %>% rolls_in_mud %>% barks_joyfully(times = 3) ``` ### Can be read as > There is a **puppy**, > And then it runs outside, > And then it rolls in the mud, > And then it barks joyfully - 3 times. --- class: middle, center, inverse # .bigger[.big[.teal[%>%]]] # your toolbox --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") ``` ] --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") monsters <- select(monsters, -hat) ``` ] --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") monsters <- select(monsters, -hat) monsters <- mutate(monsters, is_baby = age < 3) ``` ] -- **With the pipe** .bump-up[ ```r monsters <- monsters %>% * filter(., color == "pink") ``` ] --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") monsters <- select(monsters, -hat) monsters <- mutate(monsters, is_baby = age < 3) ``` ] **With the pipe** .bump-up[ ```r monsters <- monsters %>% * filter(color == "pink") ``` ] --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") monsters <- select(monsters, -hat) monsters <- mutate(monsters, is_baby = age < 3) ``` ] **With the pipe** .bump-up[ ```r monsters <- monsters %>% filter(color == "pink") %>% * select(-hat) ``` ] --- **Without the pipe** .bump-up[ ```r monsters <- filter(monsters, color == "pink") monsters <- select(monsters, -hat) monsters <- mutate(monsters, is_baby = age < 3) ``` ] **With the pipe** .bump-up[ ```r monsters <- monsters %>% filter(color == "pink") %>% select(-hat) %>% * mutate(is_baby = age < 3) ``` ] --- exclude: true ```r # Without the pipe round(log(sum(c(10, 20, 30, 50)))) # With the pipe result <- c(10, 20, 30, 50) %>% sum() %>% log() %>% round() ``` --- class: inverse, center, middle # <i class="fas fa-carrot" aria-hidden="true"></i> [Back to Videos](https://tidy-mn.github.io/R-camp-penguins/page/videos.html)