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.
Diese Übung ist Teil des Kurses
Foundations of Functional Programming with purrr
Anleitung zur Übung
- Set the names on
gh_users
using the "name" element and use themap_*()
function that outputs a character vector. - Explore the structure of
gh_repos
to see where the owner info is stored. - Set the names of a new list
gh_repos_named
based on the login of the owner of the repo, using theset_names()
andmap_*()
functions.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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(___, .)