Setting names
Setting list names makes working with lists much easier in many scenarios; it makes the code easier to read, which is especially important when reviewing code weeks or months later.
Here you are going to work with the gh_repos and gh_users datasets and set their names in two different ways. The two methods will give the same result: a list with named elements.
This exercise is part of the course
Foundations of Functional Programming with purrr
Exercise instructions
- Set the names on
gh_usersusing the "name" element and use themap_*()function that outputs a character vector. - Explore the structure of
gh_reposto see where the owner info is stored. - Set the names of a new list
gh_repos_namedbased on the login of the owner of the repo, using theset_names()andmap_*()functions.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Name gh_users with the names of the users
gh_users_named <- ___ %>%
set_names(map___(___, ___))
# Check gh_repos structure
str(___)
# Name gh_repos with the names of the repo owner
gh_repos_named <- ___ %>%
map_chr(~ .[[___]]$___$___) %>%
set_names(___, .)