validate icon indicating copy to clipboard operation
validate copied to clipboard

indicator rules read from file converted to TRUE FALSE

Open blset opened this issue 4 years ago • 5 comments

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

blset avatar Jan 24 '21 14:01 blset

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?

markvanderloo avatar Jan 25 '21 19:01 markvanderloo

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

blset avatar Jan 25 '21 20:01 blset

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)

markvanderloo avatar Jan 27 '21 20:01 markvanderloo

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.

blset avatar Jan 28 '21 10:01 blset

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.

markvanderloo avatar Jan 28 '21 10:01 markvanderloo