The error is telling you that you are trying to compare two things, but one of them is missing.
Here is a more succinct, reproducible example
x <- 1:2
x[3:4]
#[1] NA NA
while(any(x[3:4] > 0)) print(TRUE)
#Error in while (any(x[3:4] > 0)) print(TRUE) :
# missing value where TRUE/FALSE needed
Maybe you could specifically check for NAs like this
while(!any(is.na(x[3:4])) && any(x[3:4] > 0)) print(TRUE)