Utilizarea purrr în fluxul de lucru

Bazele programării funcționale cu purrr

Auriel Fournier

Instructor

Verificarea numelor

library(repurrrsive)
data(sw_films)
names(sw_films)
NULL
str(sw_films)
List of 14
 $ title        : chr ...
 $ episode_id   : int ...
 $ opening_crawl: chr ...
 $ director     : chr ...
 ...
sw_films <- sw_films %>%
  set_names(map_chr(sw_films, 
            "title"))

names(sw_films)
[1] "A New Hope"              
[2] "Attack of the Clones"   
[3] "The Phantom Menace"      
[4] "Revenge of the Sith"    
[5] "Return of the Jedi"      
[6] "The Empire Strikes Back"
[7] "The Force Awakens"
Bazele programării funcționale cu purrr

Atribuirea numelor în timpul interogărilor

map_chr(sw_films, ~.x[["episode_id"]]) %>%
  set_names(map_chr(sw_films, "title")) %>%
  sort()
  The Phantom Menace    Attack of the Clones 
                    "1"                     "2" 
    Revenge of the Sith              A New Hope 
                    "3"                     "4" 
The Empire Strikes Back      Return of the Jedi 
                    "5"                     "6" 
      The Force Awakens 
                    "7"
Bazele programării funcționale cu purrr

Să exersăm!

Bazele programării funcționale cu purrr

Preparing Video For Download...