melff / memisc

Tools for Managing Survey Data, Creating Tables of Estimates and Data Summaries
https://melff.github.io/memisc
45 stars 8 forks source link

memisc::cases(): check.xor="ignore" not working for non-exhaustive #24

Closed javrucebo closed 7 years ago

javrucebo commented 7 years ago

The help text for memisc::cases() states for the parameter check.xor: "checks, whether the case conditions are mutually exclusive and exhaustive".

In case the conditions are not exhaustive check.xor="ignore" does not work. It does issue a warning:

> x <- c(1,2)
> memisc::cases(
+   "1"=x==1,
+   "2"=x==2,
+   "3"=x==3,
+   check.xor="ignore"
+ )
[1] 1 2
Levels: 1 2 3
Warning message:
In memisc::cases(`1` = x == 1, `2` = x == 2, `3` = x == 3, check.xor = "stop") :
  condition x == 3 is never satisfied

in cases.R one should probably change (similarly to the check for done):

if(any(never) && check.xor!="ignore"){
  msg <- switch(check.xor,warn=warning,stop=stop)
  neverlab <- deflabels[never]
  if(length(neverlab)==1)
    msg("condition ",neverlab," is never satisfied")
  else
    msg("conditions ",paste(neverlab,collapse=", ")," are never satisfied")
}
melff commented 7 years ago

Thanks for reporting this bug. Fixed as suggested in f88239608aa74fe5a5156efc1b20bf9f9e7b1706