Error in function (type, msg, asError = TRUE) : Recv failure: Connection was reset
<p>I am pulling a table from a website in to Rstuidio
This is my code:</p>

<pre><code>library(XML)
library(RCurl)

get_Name_code_nation&lt;-function(k,olympicyear){
  #this function gets a number representing index which will tell us what page to
  #read(which olympic) and a year,and it returns the athletes table for that olympic.I will use a
  #loop on this function to get a table of all olympics.

  #first stage read the olympics page with all the sports in it

  URL &lt;- paste("http://www.databaseolympics.com/games/gamesyear.htm?g=",k,sep = "")
  parsed.page &lt;- htmlParse(getURL(URL))
  URL.vec &lt;- xpathSApply(parsed.page, "//a[starts-with(@href, '/games/')]",
                         xmlGetAttr, 'href')

  # second stage define variables  

  athlete_id&lt;-c()
  tab&lt;-data.frame()
  for(i in 2:length(URL.vec)){
    temp_URL&lt;-paste('http://www.databaseolympics.com',URL.vec[i],sep="")
    tab&lt;-rbind(tab,readHTMLTable(temp_URL, which=3,colClasses = 
    list(NULL,'character','factor',NULL,NULL),stringsAsFactors = FALSE))

    #part of the loop we get codes
    parsed.page.codes &lt;- htmlParse(getURL(temp_URL))
    codes.vec&lt;-xpathSApply(parsed.page.codes, "//a[starts-with(@href, '/players/')]",
    xmlGetAttr, 'href')[2:length(xpathSApply(parsed.page.codes, 
    "//a[starts-with(@href, '/players/')]",xmlGetAttr, 'href'))]
    athlete_id&lt;-c(athlete_id,sub("[^=]*=", "", codes.vec))
  }
  tab&lt;-data.frame(tab,athlete_id)
  return(tab)
}



  numbers&lt;-c(1:26,47)
  years&lt;-c(1896,1900,1904,1906,1908,1912,1920,1924,1928,1932,1936,seq(1948,2008,4))
  athletes.df&lt;-data.frame()
  for(i in 1:length(numbers)){
  athletes.df&lt;-rbind(athletes.df,get_Name_code_nation(numbers[i],years[i]))
}
</code></pre>

<p>I run this program many times and most of the time everything is ok, the code runs with no problems and the data comes in as it should. The issue is that once in a while I get a weird error and it looks like the program stopped at the middle and only some of the data comes in
Those are the diffrent errors I get:</p>

<pre><code>Error in function (type, msg, asError = TRUE)  : 
  Recv failure: Connection was reset 

Error in function (type, msg, asError = TRUE)  : 
  connection timed out 80

 Error in UseMethod("xmlNamespaceDefinitions") : 
  no applicable method for 'xmlNamespaceDefinitions' applied to an object of class "NULL"
</code></pre>

<p>If it would have never worked I would say there is a problem with the code but most of the time it works, I have no idea what affects it and causes it to work or not work.</p>

<p>Does anybody have an idea if it could be something related to the website? And is there anything I can do?</p>