Skip to content

Commit

Permalink
some more content
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Apr 21, 2024
1 parent 681f188 commit bad5ca6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ knitr::opts_chunk$set(
[![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 to ...
The goal of slap is simplify error handling.

## Installation

You can install the development version of slap like so:

``` r
pak::pak("tadascience/slap")
```
Expand All @@ -37,20 +35,24 @@ pak::pak("tadascience/slap")
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())
# instead of:
# 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)
}
)
# just use the slap operator, i.e. %!%
# 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 use the double slap operator for simpler error
# i.e. without keeping the parent error
# or the double slap operator %!!% if you don't want to keep the parent error
summarise(mtcars, mpg = boom()) %!!% "ouch"
```
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ status](https://www.r-pkg.org/badges/version/slap)](https://CRAN.R-project.org/p
[![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 to …
The goal of slap is simplify error handling.

## Installation

You can install the development version of slap like so:

``` r
pak::pak("tadascience/slap")
```
Expand All @@ -28,20 +26,24 @@ pak::pak("tadascience/slap")
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())

# instead of:
# 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)
}
)

# just use the slap operator, i.e. %!%
# 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 use the double slap operator for simpler error
# i.e. without keeping the parent error
# or the double slap operator %!!% if you don't want to keep the parent error
summarise(mtcars, mpg = boom()) %!!% "ouch"
```

0 comments on commit bad5ca6

Please sign in to comment.