找出問題區域
當你在處理小型清單時,手動逐一檢查並找出哪個元素有問題,似乎不會花太多力氣。但如果清單有數百或數千個元素,你就會希望把這個流程自動化。
現在你會面對一個較大的清單,看看錯誤訊息如何幫助你檢查整個清單並找出問題。
本練習屬於課程
使用 purrr 的函式式程式設計基礎
練習說明
- 對
sw_people使用map()並取出「height」元素。 - 搭配
safely()使用map(),把身高由公分換算成英尺。 - 設定
quiet = FALSE,讓錯誤會被印出。 - 再接到
transpose(),先列印結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Map over sw_people and pull out the height element
height_ft <- map(___ , ___) %>%
map(safely(function(___){
___ * 0.0328084
}, quiet = ___)) %>%
___
# Print your list, the result element, and the error element
height_ft
height_ft[["result"]]
height_ft[["error"]]