Manipulating URLs

Intermediate Functional Programming with purrr

Colin Fay

Data Scientist & R Hacker at ThinkR

Creating mappers

as_mapper()

library(purrr)
mult <- as_mapper(~ .x * 2)
map(list(airquality, mtcars), 
    mult)
[[1]]
    Ozone Solar.R Wind Temp Month Day
1      82     380 14.8  134    10   2
2      72     236 16.0  144    10   4
3      24     298 25.2  148    10   6
4      36     626 23.0  124    10   8
5      NA      NA 28.6  112    10  10
6      56      NA 29.8  132    10  12
... 
Intermediate Functional Programming with purrr

stringr::str_detect()

Pattern detection:

library(stringr)
lyrics <- c("Is this the real life?", 
            "Is this just fantasy?", 
            "Caught in a landslide", 
            "No escape from reality")
str_detect(lyrics, "life")
TRUE FALSE FALSE FALSE
Intermediate Functional Programming with purrr

Side note on logicals

Summing logicals:

sum(FALSE, TRUE, TRUE, FALSE, TRUE)
3
Intermediate Functional Programming with purrr

Let's practice!

Intermediate Functional Programming with purrr

Preparing Video For Download...