-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
92 lines (67 loc) · 2.79 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
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%"
)
```
# stbl
<!-- 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/stbl)](https://CRAN.R-project.org/package=stbl)
[![Codecov test coverage](https://codecov.io/gh/jonthegeek/stbl/branch/main/graph/badge.svg)](https://app.codecov.io/gh/jonthegeek/stbl?branch=main)
[![R-CMD-check](https://github.com/jonthegeek/stbl/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jonthegeek/stbl/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
R is flexible about classes.
Variables are not declared with explicit classes, and arguments of the "wrong" class don't cause errors until they explicitly fail at some point in the call stack.
It would be helpful to keep that flexibility from a user standpoint, but to error informatively and quickly if the inputs will not work for a computation.
The purpose of stbl is to allow programmers to specify what they want, and to then see if what the user supplied can work for that purpose.
## Installation
::: {.pkgdown-release}
Install the released version of stbl from [CRAN](https://cran.r-project.org/):
``` r
install.packages("stbl")
```
:::
::: {.pkgdown-devel}
Install the development version of stbl from [GitHub](https://github.com/):
``` r
# install.packages("pak")
pak::pak("jonthegeek/stbl")
```
:::
## Usage
Use within functions to give meaningful error messages for bad argument classes.
For example, perhaps you would like to protect against the case where data is not properly translated from character on load.
### Without stbl:
Without the argument-stabilizers provided in stbl, error messages can be cryptic, and errors trigger when you might not want them to.
```{r no-stbl, error = TRUE}
my_old_fun <- function(my_arg_name) {
my_arg_name + 1
}
my_old_fun("1")
```
### With stbl:
stbl helps to ensure that arguments are what you expect them to be.
```{r with-stbl-ok}
my_fun <- function(my_arg_name) {
my_arg_name <- stbl::to_int(my_arg_name)
my_arg_name + 1
}
my_fun("1")
```
Failures are reported with helpful messages.
```{r with-stbl-error1, error = TRUE}
my_fun("1.1")
```
The errors help locate issues within vectors.
```{r with-stbl-error2, error = TRUE}
my_fun(c("1", "2", "3.1", "4", "5.2"))
```
## Code of Conduct
Please note that the stbl project is released with a [Contributor Code of Conduct](https://jonthegeek.github.io/stbl/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.