garner-code / PSY2R

translating PSY to R
3 stars 16 forks source link

need some example code on how to test variables and correctly throw errors or warnings when tests fal #49

Open garner-code opened 1 week ago

MashaPtukha commented 1 week ago

stopping the code and throwing an error if condition is not met:

if (x != y) { stop("Error: x is not equal to y") }

throwing a warning if condition is not met, but continuing with the code execution:

if (x < 0) { warning("Warning: x is negative, which may lead to unexpected behavior.") }