As stated in the title, I have two separate if statements in my R code. The first is functioning properly, but the second is being treated as if it is always true, even when it isn't. Here's the relevant code:
narrowed <- reactive({
nar <- data.frame(ref.range())
exl <- which(nar$Result < input$minimum)
if(length(exl) >= 1){
nar <- nar[-exl,]
}
exh <- which(nar$Result > input$maximum)
if(length(exh) >= 1){
nar <- nar[-exh,]
}
})
When the Shiny App plots the data in the narrowed() dataframe, it is apparent that it is excluding exh from the data, whether exh has a length >0 or not. However, it is only excluding exl from the data when exl has a length >0. I know it's only evaluating the first if statement because if I put the exh-related lines first, it excludes exl all the time but only excludes exh when it has a length >0.
I tried splitting it into two separate reactive functions so it looked like this:
narrow <- reactive({
nar <- data.frame(ref.range())
exl <- which(nar$Result < input$minimum)
if(length(exl) >= 1){
nar <- nar[-exl,]
}
})
narrowed <- reactive({
narr <- data.frame(narrow())
exh <- which(narr$Result > input$maximum)
if(length(exh) >= 1){
nar <- nar[-exh,]
}
})
but that gave the error "evaluation nested too deeply: infinite recursion / options(expressions=)?" So dividing the work between two subsets is not the answer. I have written other R scripts with separate if statements like what I have here with no issue, so I don't know what the problem is. Any help would be greatly appreciated.