Skip to content

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

License

Notifications You must be signed in to change notification settings

FinnishCancerRegistry/dbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Recommended installation

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

Example

# 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")
}