An open API service indexing awesome lists of open source software.

https://github.com/tadascience/slap

Slap Light Alternative Plight
https://github.com/tadascience/slap

bat batman error-handling r slap

Last synced: 4 months ago
JSON representation

Slap Light Alternative Plight

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# slap

[![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)

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"
```