處理副詞結果

使用 purrr 的 R 語言中級函式程式設計

Colin Fay

Data Scientist & R Hacker at ThinkR

安全清理結果

transpose() 轉換結果:

# Transpose turn a list of n elements a and b 
# to a list of a and b, with each n elements
l <- list("a", 2, 3)
map(l, safe_log) %>% length()
3
map(l, safe_log) %>% transpose() %>% length()
2
使用 purrr 的 R 語言中級函式程式設計

關於 compact()

compact() 會移除 NULL

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

[[2]]
[1] 3

[[3]]
[1] 4
使用 purrr 的 R 語言中級函式程式設計

possibly() 與 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
使用 purrr 的 R 語言中級函式程式設計

溫和導覽:httr 入門

使用 purrr 的 R 語言中級函式程式設計

一起來練習吧!

使用 purrr 的 R 語言中級函式程式設計

Preparing Video For Download...