title: Error in open.connection Timeout was reached
body: <p>I have this currently working. Im new to R so idk how connections work and its one thing google didnt help.</p>
  
  <p>My code gets me numbers from a crest api.</p>
  
  <pre><code>df &lt;- readWorksheetFromFile("marketTypeIDS.xls", sheet=1, startRow = 1, endCol = 2)
  
  typeIDs &lt;- unname(unlist(df[,1]))
  
  calcday&lt;-as.numeric(Sys.Date())-30
  currentdate&lt;-as.numeric(Sys.Date())
  
  itemcount &lt;- 0
  monthvolumes &lt;- seq(1:11897)
  
  baseurl &lt;- "https://public-crest.eveonline.com/market/10000048/types/"
  
  monthlyvolume &lt;- (0)
  
  tmpvol &lt;- (0)
  
  for (i in 1:11897) 
      {
      itemcount &lt;- fromJSON(paste0(baseurl, typeIDs[i], "/history/"), flatten = TRUE)$totalCount
      Sys.sleep(0.034)
      if (itemcount ==0)
      {
      monthvolumes[i] &lt;- 0
      }
      else 
          {
          repeat
              {
              currentdate &lt;- as.Date(fromJSON(paste0(baseurl, typeIDs[i], "/history/"), flatten = TRUE)$items[itemcount,8])
              Sys.sleep(0.034)                    
              if (as.numeric(currentdate)&lt;calcday)
                  {
                  break
                  }
              tmpvol &lt;- fromJSON(paste0(baseurl, typeIDs[i], "/history/"), flatten = TRUE)$items[itemcount,6]
              Sys.sleep(0.034)
              monthlyvolume &lt;- monthlyvolume+tmpvol
              itemcount &lt;- itemcount-1
              if (itemcount==0)
                  {
                  break
                  }
              }               
          monthvolumes[i]&lt;-monthlyvolume
          monthlyvolume&lt;-0
          }                                           
      }
  </code></pre>
  
  <p>It stops at ~700 (should do it over 11000 times tho) and then gives me this error:</p>
  
  <pre><code> Error in open.connection(con, "rb") : Timeout was reached 
  6 open.connection(con, "rb") 
  5 open(con, "rb") 
  4 parse_con(txt, 1024^2, bigint_as_char) 
  3 parseJSON(txt, bigint_as_char) 
  2 fromJSON_string(txt = txt, simplifyVector = simplifyVector, simplifyDataFrame = simplifyDataFrame, 
      simplifyMatrix = simplifyMatrix, flatten = flatten, ...) 
  1 fromJSON(paste0(baseurl, typeIDs[i], "/history/"), flatten = TRUE) 
  In addition: Warning message:
  closing unused connection 3 (https://public-crest.eveonline.com/market/10000048/types/18/history/) 
  </code></pre>
  
  <p>This connection was created on the first run of the for loop (it starts with the 18 in the link)
  How could I close this connection beforehand so it doesnt break the loop? (this just ran about an hour so its hard to test through "trying")</p>
  
  <p>Thanks for help in advance!
  If u have any other suggestions my ears are open!</p>