Intermediate Functional Programming with purrr
Colin Fay
Data Scientist & R Hacker at ThinkR
rstudioconf
: a list of 5055 tweets
length(rstudioconf)
length(rstudioconf[[1]])
5055
31
library(purrr)
vec_depth(rstudioconf)
4
Source : ThinkR-open/datasets
JSON == nested lists
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{ "value": "New", "onclick": "CreateNewDoc" },
{ "value": "Open", "onclick": "OpenDoc" },
{ "value": "Close", "onclick": "CloseDoc" }
]
}
}
}
We've seen:
map_*()
discard()
keep()
Predicate functionals:
keep()
the elements that meet a condition:
keep(1:10, ~ .x < 5)
1 2 3 4
discard()
the elements that meet a condition:
discard(1:10, ~ .x < 5)
5 6 7 8 9 10
Intermediate Functional Programming with purrr