checkmate icon indicating copy to clipboard operation
checkmate copied to clipboard

add infrastructure for consistency checks BETWEEN arguments

Open maxheld83 opened this issue 8 years ago • 1 comments

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:

  • their names (identical.to, subset.of, permutation.of)
  • their dimensions -...

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:

  • the error messages are often not very informative (as in #94)
  • ... and it's not clear (to me) how to build better error messages and their downstream artefacts (to assert_, test_, and expect_ as well as testthat()and assert() collections/reporters.

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 avatar Dec 09 '16 17:12 maxheld83

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.
}

maxheld83 avatar Dec 09 '16 17:12 maxheld83