-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
58 lines (45 loc) · 1.68 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# slap <a href="https://slap.tada.science"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/slap)](https://CRAN.R-project.org/package=slap)
[![R-CMD-check](https://github.com/tadascience/slap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tadascience/slap/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of slap is simplify error handling.
## Installation
``` r
pak::pak("tadascience/slap")
```
## Example
```{r, eval = FALSE}
library(dplyr)
library(slap)
# suppose you have a function that throws an error
boom <- function() stop("An error occured in boom()")
# and you want to use it in e.g. dplyr::summarise()
# summarise(mtcars, mpg = boom())
# if you want to catch it and rethrow an error that is more
# meaningful to you, one way is to use withCallingHandlers()
withCallingHandlers(
summarise(mtcars, mpg = boom()),
error = function(err) {
cli::cli_abort("ouch", parent = err)
}
)
# but that's kind of boring, so instead you can use the
# slap operator %!% to slap away the eror
summarise(mtcars, mpg = boom()) %!% "ouch"
# or the double slap operator %!!% if you don't want to keep the parent error
summarise(mtcars, mpg = boom()) %!!% "ouch"
```