Gérer les résultats des adverbes

Programmation fonctionnelle intermédiaire avec purrr

Colin Fay

Data Scientist & R Hacker at ThinkR

Nettoyer les résultats en toute sécurité

Transformer le résultat avec transpose() :

# transpose convertit une liste de n éléments a et b 
# en une liste de a et b, chacun avec n éléments
l <- list("a", 2, 3)
map(l, safe_log) %>% length()
3
map(l, safe_log) %>% transpose() %>% length()
2
Programmation fonctionnelle intermédiaire avec purrr

À propos de compact()

compact() enlève les NULL :

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

[[2]]
[1] 3

[[3]]
[1] 4
Programmation fonctionnelle intermédiaire avec purrr

possibly() et 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
Programmation fonctionnelle intermédiaire avec purrr

Introduction simple à httr

Programmation fonctionnelle intermédiaire avec purrr

Passons à la pratique !

Programmation fonctionnelle intermédiaire avec purrr

Preparing Video For Download...