I have code using an if statement to evaluate whether a value is greater than .25. Occasionally, the lead up code would submit two records for evaluation that were equal. My if statement would execute with a warning "the condition has length > 1, and only the first element will be used" This was acceptable behavior for my application and so I threw a suppressWarnings around the evaluation and moved on. Today, after updating to R 4.2.0 the same code generates an error "Error in if ....: the condition has length > 1
I can't find documentation on the change (probably because it is new). Suggestions on how to circumvent this or any explanation of what is going on would be helpful. FWIW there is a lot more that is happening in the if statement, so a switch to ifelse is not really practical here. Here is some replicable code:
a<-c(1,1)
b<-1
if(b > .25){print(b)}
if(a > .25){print(a)}
Output:
> a<-c(1,1)
> b<-1
> if(b > .25){print(b)}
[1] 1
> if(a > .25){print(a)}
Error in if (a > 0.25) { : the condition has length > 1
>
I would like
suppressWarnings(if(a > .25){print(a)})
to print a