0

I have the following code executing in my server function:

``

# Integral of xf(x)
Sxfx <- 0

for(i in 1:501)
{
  
  sumxfx <- 0
  
  for(j in 1:i)
  {
    sumxfx <- sumxfx + xfx[j]
  }
  
  Sxfx[i] <- sumxfx
  
}

``

When I execute it, I get the following error message:

Warning: Error in if: missing value where TRUE/FALSE needed [No stack trace available]

Any tips on how to fix this? The vector it relates to lengthwise is c(0:500).

I previously got an error about the differing number of rows, when my loop was going 1:500. With that error, my file wouldn't execute at all. So I changed it to the current loop going 1:501, and the error message changed to this.

Any help will be greatly appreciated!

  • I've seen that error only in `if` statements, nothing in this code suggests that error. For `if` statements, it is a frequent question, https://stackoverflow.com/search?tab=votes&q=%5br%5d%20missing%20value%20where%20TRUE%2fFALSE%20needed. – r2evans Sep 19 '20 at 23:44
  • 1
    I understand you're trying something in `shiny`, but that error is likely in base R stuff, not `shiny` ... and you've provided little code, no data, and no context in `shiny`. Please make this question self-contained and reproducible. This includes code *that actually triggers the error* (including listing non-base R packages) and sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`) that can be used to reproduce the error. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Sep 19 '20 at 23:47

1 Answers1

0

I have found this to be a problem in checkboxes where instead of having the input$function==1 I typed {r} input$function ==TRUE

the input$function==1 is the better choice.