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

https://github.com/finnishcancerregistry/dbc

Design-by-contract: verify your function inputs and outputs. Includes a large number of generated verifcation functions for convenience.
https://github.com/finnishcancerregistry/dbc

assertions contract-programming data-validation defensive-programming design-by-contract error-checking function-validation input-validation output-validation r r-package runtime-validation

Last synced: 3 months ago
JSON representation

Design-by-contract: verify your function inputs and outputs. Includes a large number of generated verifcation functions for convenience.

Awesome Lists containing this project

README

        

# Package `dbc`

`dbc` is designed to aid writing functions under the design by contract
philosophy, where function inputs and outputs are programmatically
asserted to adhere to specifications.

[![R-CMD-check](https://github.com/FinnishCancerRegistry/dbc/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/FinnishCancerRegistry/dbc/actions/workflows/R-CMD-check.yaml)

# Recommended installation

```r
devtools::install_github(
"FinnishCancerRegistry/dbc",
ref = readline("enter latest tag on github: ")
)
```

# Example
```r
# by adding arg assertion_type, you can use the same function for end-user
# purposes and internal purposes with clear error messages.
my_fun <- function(df, by, assertion_type = NULL) {
dbc::assert_is_character_nonNA_vector(
x = by,
assertion_type = assertion_type
)
dbc::assert_is_data_frame_with_required_names(
x = df,
required_names = by,
assertion_type = assertion_type
)
return(table(df[,by]))
}
my_fun(df, c("var_1", "var_2"))
my_fun_2 <- function(df) {
my_fun(df, c("var_1", "var_2"), assertion_type = "prod_input")
}
```