Fortgeschrittene funktionale Programmierung mit purrr
Colin Fay
Data Scientist & R Hacker at ThinkR
`possibly() erstellt eine Funktion, die entweder Folgendes zurückgibt:
das Ergebnis
den Wert von otherwise
library(purrr) possible_sum <- possibly(sum, otherwise = "nop") possible_sum(1)possible_sum("a")
0"nop"
possibly() kann zurückgeben:
ps <- possibly(sum, FALSE)
ps("a")
FALSE
NAps <- possibly(sum, NA)
ps("a")
NA
ps <- possibly(sum, "nope")
ps("a")
"nope"
ps <- possibly(sum, 0)
ps("a")
0
Fortgeschrittene funktionale Programmierung mit purrr