title: How to determine the cause of, Error in if: missing value where TRUE/FALSE needed, that only occurs when running as Shiny App
body: <p>I'm working on a map project and have plotted two datasets of markers in a leaflet map (shiny app).  One dataset is larger than the other, and I'm drawing great circle arcs connecting the many to few.  Everything was working fine.  I updated R from 3.5 to 3.6 and now I get "Error in if: missing value where TRUE/FALSE needed" which I have isolated to the for statement that runs the great circle arcs.</p>
  
  <p>Hard coding values into gcIntermediate() works but then I can only have 1 fixed arc.  Making a new dataframe with values works, but the data.frame built from my imported data no longer works.</p>
  
  <pre><code># inside server.R
  output$MapNet &lt;-   renderLeaflet({
      leaflet() %&gt;%
        addTiles(
          urlTemplate = "http://mt0.google.com/vt/lyrs=m&amp;hl=en&amp;x={x}&amp;y={y}&amp;z={z}&amp;s=Ga", 
          attribution = 'Google'
        ) %&gt;%
        setView(lng = -93.85, lat = 37.45, zoom = 5)
    })  
  
  
  NetData &lt;- data.frame(PRgps.lon = c(-83.35300,-82.52681,-82.31592,-82.91263,-83.61500,-82.73041,-82.73041,-82.73041,-82.73041,-82.73041),
                        PRgps.lat = c(42.97400, 45.46538, 45.45996, 45.40823, 45.25417, 45.51366, 45.51366, 45.51366, 45.51366, 45.51366),
                        JCgps.lon = c(-82.68287,-81.63665,-81.96928,-81.96928,-81.96928,-82.92507,-81.96928,-82.61287,-81.06040,-81.63665),
                        JCgps.lat = c(45.68083, 45.66951, 45.58777, 45.58777, 45.58777, 45.24366, 45.58777, 45.68083, 44.65540, 45.66951),
                        popup = c("A", "P", "M", "M", "J  ", "M", "M", "M", "M", "M")
                        )    
  
  arcbuilder(NetData, MapNet)
  
  </code></pre>
  
  <pre><code># Inside global.R
  arcbuilder &lt;- function(NetData, MapNet){
    for (i in 1:nrow(NetData)) {
  
      arc &lt;- as.data.frame(gcIntermediate(c(NetData[i,]$PRgps.lon, NetData[i,]$PRgps.lat), 
                                          c(NetData[i,]$JCgps.lon, NetData[i,]$JCgps.lat), 
                                          n = 100, addStartEnd = TRUE ))
  
      MapNet &lt;- MapNet %&gt;% 
        addPolylines(lat = arc$lat,
                     lng = arc$lon,
                     color = "green",
                     weight = 2,
                     popup = NetData[i,]$popup)
  
    }
  }
  
  </code></pre>
  
  <p>The code above works, the data provided as NetData is the head(10) of the imported NetData.  The num and chr aspects are the same as the proper file when left alone in that manor.  When I don't hard enter it, and feed 100's of rows of data into the for loop I get the Warning: Error in if: missing value where TRUE/FALSE needed.  More specifically I get:</p>
  
  <pre><code>Warning: Error in if: missing value where TRUE/FALSE needed
    48: .interm
    47: gcIntermediate
    45: arcbuilder [C:\Users\me\Documents\GitHub\Network_Map/global.R#193]
    44: &lt;observer&gt; [C:\Users\me\Documents\GitHub\Network_Map/server.R#136]
     1: runApp
  </code></pre>
  
  <p>Where Line #136 is where arcbuilder() is called in server.R and Line 193 is where gcIntermediate() is used inside arcbuilder() in global.R</p>
  
  <p>Lastly, when running the entire NetData data.frame into the arcbuilder function with a map setup to work outside of shiny, it runs without error.  I have checked the data from NAs or other anomalies and I'm reasonably confident there aren't any.</p>
  
  <p>What am I missing?</p>