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
- Host: GitHub
- URL: https://github.com/tadascience/slap
- Owner: tadascience
- License: other
- Created: 2024-04-06T14:43:57.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-02T07:51:08.000Z (about 2 years ago)
- Last Synced: 2025-12-09T11:48:47.260Z (7 months ago)
- Topics: bat, batman, error-handling, r, slap
- Language: R
- Homepage: http://slap.tada.science/
- Size: 1.37 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
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%"
)
```
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://CRAN.R-project.org/package=slap)
[](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"
```
