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.
- Host: GitHub
- URL: https://github.com/finnishcancerregistry/dbc
- Owner: FinnishCancerRegistry
- License: other
- Created: 2020-06-25T06:36:18.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-12T10:12:16.000Z (4 months ago)
- Last Synced: 2025-02-12T11:27:35.746Z (4 months ago)
- Topics: assertions, contract-programming, data-validation, defensive-programming, design-by-contract, error-checking, function-validation, input-validation, output-validation, r, r-package, runtime-validation
- Language: R
- Homepage:
- Size: 1.44 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
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.[](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")
}
```