validate
validate copied to clipboard
indicator rules read from file converted to TRUE FALSE
Hello trying to read indicator rules from file
with indicator (.file = filename) a rule like the one below is converted to TRUE / FALSE so the min is always 0 , the max is 1 and the mean is some proportion , not clear which one from the rule below,
rules:
- expr: if(a > 2) a / b
- expr: a/b
Best regards
Hi there,
that looks like unintended behavior. But I am not 100%
sure what you would like the rule to do.
Do you want it to compute a/b
when a>2
? But what about cases where a<=2
?
Hi the use case is this one
I want to compute a ratio but only when the denominator is not null
with two numeric variables a and b sometimes NA I want (a - b) / a , but only when a >0 and when a and b not NA
thanks
Still, the question is what you want returned when a<=0 or a and/or b is NA. If you want NA
as a result in that case, you can use ifelse
:
ifelse( a>0 & !is.na(a) &!is.na(b), (a-b)/a, NA)
NA is ok, so for my use case that works ok with ifelse
does it mean the construct with if
will always be converted to TRUE FALSE with indicator rules ?
and so is not very useful in contrary to ifelse
what about
rules:
- expr: if (cond) compute1
that would also give NA when cond is not met, and would compute otherwise.
Yes, the way if()
is treated is the same as in validator
objects, but that may or may not be desirable. I don't think we've given this a lot of thought yet. Your suggestion looks interesting though.