mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
262 stars 30 forks source link

add infrastructure for consistency checks BETWEEN arguments #95

Open maxheld83 opened 7 years ago

maxheld83 commented 7 years ago

I often find myself in the situation where I do not just want to assert() something about an argument, but rather, whether two (or more) arguments are consistent, including, for example:

This shows up especially when validating classes (as suggested in #92).

checkmate() in its current form can be shoehorned into this service, but there are some issues:

I have only an anecdotal grasp of the problem, so I don't know what a good interface (let alone implementation) would look like. I mainly just wanted to raise this here to see whether you might consider this in the future.

maxheld83 commented 7 years ago

perhaps, a somewhat off-the-cuff suggestion, after all (of the interface):

check_consistency(x,  # object 1,
                  y,  # object 2,
                  # all of the following conditions must be read as: x blah-condition y
                  length = TRUE,  # could also be "smaller", "larger"
                  # interpreted as, e.g. x smaller y
                  names = "subset.of",
                  # interpreted as, e.g. x subset.of y 
                  ncol = TRUE,  # could also be "smaller"
                  nrow = TRUE, 
                  colnames = "identical.to",  # etc
                  rownames = "identical.to", # etc
) {
  # here be dragons
  return(paste(vname(x), "must be shorter than", vname(y)))  # etc.
}