Handling adverb results

Intermediate Functional Programming with purrr

Colin Fay

Data Scientist & R Hacker at ThinkR

Cleaning safely results

Transform the result with transpose() :

# Transpose turn a list of n elements a and b 
# to a list of a and b, with each n elements
l <- list("a", 2, 3)
map(l, safe_log) %>% length()
3
map(l, safe_log) %>% transpose() %>% length()
2
Intermediate Functional Programming with purrr

About compact()

compact() removes the NULL:

list(1, NULL, 3, 4, NULL) %>%
  compact()
[[1]]
[1] 1

[[2]]
[1] 3

[[3]]
[1] 4
Intermediate Functional Programming with purrr

possibly() and compact()

otherwise = NULL %>% compact():

l <- list(1,2,3,"a")
possible_log <- possibly(log, otherwise = NULL)
map(l, possible_log) %>% compact()
[[1]]
[1] 0

[[2]]
[1] 0.6931472

[[3]]
[1] 1.098612
Intermediate Functional Programming with purrr

A Gentle introduction to httr

Intermediate Functional Programming with purrr

Let's practice!

Intermediate Functional Programming with purrr

Preparing Video For Download...