https://github.com/poissonconsulting/err
An R package to produce customizable number sensitive error and warning messages
https://github.com/poissonconsulting/err
cran errors messages r warnings
Last synced: 2 months ago
JSON representation
An R package to produce customizable number sensitive error and warning messages
- Host: GitHub
- URL: https://github.com/poissonconsulting/err
- Owner: poissonconsulting
- License: other
- Created: 2018-08-23T17:13:13.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2022-06-17T21:54:15.000Z (over 3 years ago)
- Last Synced: 2024-06-23T19:22:23.026Z (over 1 year ago)
- Topics: cran, errors, messages, r, warnings
- Language: R
- Homepage: https://poissonconsulting.github.io/err/
- Size: 328 KB
- Stars: 7
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# err
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/poissonconsulting/err/actions)
[](https://codecov.io/github/poissonconsulting/err?branch=master)
[](https://opensource.org/license/mit/)
[](https://cran.r-project.org/package=err)

## Introduction
> To err is human - Alexander Pope (1711)
`err` is a light-weight R package to produce customizable number and object sensitive error and warning messages.
## Demonstration
### Object Sensitive
The `co` functions produce object sensitive strings.
```{r}
library(err)fox <- c("The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog")
co(fox)
co(fox[1])
co(fox[0])
co(fox, nlots = 5)
```### Customizable
The object sensitive strings are fully customized.
```{r}
one <- "darn! the vector %o of length %n has the following value: %c"
none <- "phew! vector %o is empty"
some <- "rats! vector %o has the following %n element%s: %c"
lots <- "really?! the %n elements of vector %o are too numerous to print"co(fox[0], one = one, none = none, some = some, lots = lots, nlots = 5)
co(fox[1], one = one, none = none, some = some, lots = lots, nlots = 5)
co(fox[1:3], one = one, none = none, some = some, lots = lots, nlots = 5)
co(fox[1:5], one = one, none = none, some = some, lots = lots, nlots = 5)
```The following `sprintf`-like types can be used in the custom messages:
- `%c`: the object as a comma separated list (produced by a `cc` function)
- `%n`: the length of the object
- `%o`: the name of the object
- `%s`: 's' if n != 1 otherwise ''
- `%r`: 'are' if n != 1 otherwise 'is'And there are various formatting options
```{r}
co(fox[1:6], conjunction = "or", bracket = "|", oxford = TRUE, ellipsis = 5)
```### Data Frames
There is also a method for data frames.
```{r}
cat(co(datasets::mtcars, conjunction = "and", oxford = TRUE, ellipsis = 5))
```### Number Sensitive
The `cn` function produces number sensitive customizable messages
```{r}
cn(0)
cn(1)
cn(2)
cn(100, lots = "there %r %n value%s - this is a lot")
```### Warning and Error Messages
The `co` and `cn` functions can be combined with the wrappers `msg`, `wrn` and `err` to produce a message, warning and error (without the call as part of the warning/error message).
```{r, error = TRUE}
msg(cn(2))
wrn(cn(2))
err(cn(2))
```## Installation
To install the latest release version from [CRAN](https://cran.r-project.org)
```
install.packages("err")
```To install the latest development version from [GitHub](https://github.com/poissonconsulting/err)
```
if(!"devtools" %in% installed.packages()[,1])
install.packages("devtools")
devtools::install_github("poissonconsulting/err")
```## Inspiration
[`concatenate`](https://github.com/jamesdunham/concatenate) by [James Dunham](https://github.com/jamesdunham)
## Contribution
Please report any [issues](https://github.com/poissonconsulting/err/issues).
[Pull requests](https://github.com/poissonconsulting/err/pulls) are always welcome.
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).
By participating in this project you agree to abide by its terms.## Code of Conduct
Please note that the err project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.