moodymudskipper / flow

View and Browse Code Using Flow Diagrams
https://moodymudskipper.github.io/flow/
Other
395 stars 26 forks source link

stopifnot #87

Open moodymudskipper opened 2 years ago

moodymudskipper commented 2 years ago

We already have swap = TRUE to change foo <- if(cond) "a" else "b" to if(cond) foo <- "a" else foo <- "b".

It would make sense to make stopifnot diagram friendly too.

stopifnot has some advanced options (usually not used), and a small difference with if(cond) stop() in that the conditions are not coerced to logical.

So stopifnot(cond) seems equivalent to if(!isTRUE(cond)) stop("`cond` is not TRUE").

stopifnot(cond1, cond2) seems equivalent to :

if(!isTRUE(cond1)) {
  stop("`cond1` is not TRUE")
} else if(!isTRUE(cond2)) {
  stop("`cond2` is not TRUE")
}

We might just not support more advanced uses since they're not obvious to translate and rarely used.