# A tibble: 4 × 3
# Groups: sex [2]
sex statistic mass
<chr> <chr> <dbl>
1 female average 56.3
2 female st_dev 16.3
3 male average 90.5
4 male st_dev 19.8
Funções (4/4)
Resumindo
fácil de testar ({testthat})
fácil de documentar ({roxygen2})
fácil de empacotar ({devtools}, {usethis})
podem ser compostas (h |> f |> g)
Limites das funções (1/6)
Difícil de gerir efeitos colaterais (side-effects)
# logging_sqrt(): lista de resultados (sem mais efeito colateral)logging_sqrt <-function(x, log =""){list(sqrt(x),c(log,paste0("Running sqrt with input ", x)))}logging_sqrt(16)
OK! Value computed successfully:
---------------
Just
# A tibble: 9 × 3
# Groups: species [9]
species sex mass
<chr> <chr> <dbl>
1 Clawdite female 55
2 Droid none 69.8
3 Human female 56.3
4 Hutt hermaphroditic 1358
5 Kaminoan female NaN
6 Mirialan female 53.1
7 Tholothian female 50
8 Togruta female 57
9 Twi'lek female 55
---------------
This is an object of type `chronicle`.
Retrieve the value of this object with pick(.c, "value").
To read the log of this object, call read_log(.c).
chronicler monad (3/6)
read_log(output)
[1] "Complete log:"
[2] "OK! select(height,mass,species,sex) ran successfully at 2023-06-07 12:14:00"
[3] "OK! group_by(species,sex) ran successfully at 2023-06-07 12:14:00"
[4] "OK! filter(sex != \"male\") ran successfully at 2023-06-07 12:14:00"
[5] "OK! summarise(mean(mass, na.rm = TRUE)) ran successfully at 2023-06-07 12:14:00"
[6] "Total running time: 0.0813939571380615 secs"
NOK! Value computed unsuccessfully:
---------------
Nothing
---------------
This is an object of type `chronicle`.
Retrieve the value of this object with pick(.c, "value").
To read the log of this object, call read_log(.c).
chronicler monad (6/6)
read_log(output)
[1] "Complete log:"
[2] "OK! select(height,mass,species,sex) ran successfully at 2023-06-07 12:14:01"
[3] "OK! group_by(species,sex) ran successfully at 2023-06-07 12:14:01"
[4] "NOK! filter(sex_wrong != \"male\") ran unsuccessfully with following exception: ℹ In argument: `sex_wrong != \"male\"`.\nℹ In group 1: `species = \"Aleena\"`, `sex = \"male\"`.\nCaused by error:\n! object 'sex_wrong' not found at 2023-06-07 12:14:01"
[5] "NOK! summarise(mean(mass, na.rm = TRUE)) ran unsuccessfully with following exception: Pipeline failed upstream at 2023-06-07 12:14:01"
[6] "Total running time: 0.320563077926636 secs"