I am trying to get a code to grab all NBA box scores for the month of October. I want the code to try every URL possible for the combination of dates (27-31) and the 30 teams. However, as not all of the teams play every day, some combinations won't exist, so I am trying to implement the try function to skip the non-existent URLs, but I cant seem to figure it out. Here is what I have written so far:

```
install.packages("XML")
library(XML)

teams = c('ATL','BKN','BOS','CHA','CHI',
      'CLE','DAL','DEN','DET','GS',
      'HOU','IND','LAC','LAL','MEM',
      'MIA','MIL','MIN','NOP','NYK',
      'OKC','ORL','PHI','PHX','POR',
      'SAC','SA','TOR','UTA','WSH')

october = c()

for (i in teams){
  for (j in (c(27:31))){
    url = paste("http://www.basketball-reference.com/boxscores/201510",
                     j,"0",i,".html",sep = "")
    data <- try(readHTMLTable(url, stringsAsFactors = FALSE))

    if(inherits(data, "error")) next

    away_1 = as.data.frame(data[1])
    colnames(away_1) = c("Players","MP","FG","FGA","FG%","3P","3PA","3P%","FT","FTA",
    "FT%", "ORB","DRB","TRB","AST","STL","BLK","TO","PF","PTS","+/-")

    away_1 = away_1[away_1$Players != "Reserves",]
    away_1 = away_1[away_1$MP != "Did Not Play",]

    away_1$team = rep(toupper(substr(names(as.data.frame(data[1]))[1], 
                           5, 7)),length(away_1$Players))
    away_1$loc = rep(i,length(away_1$Players))

    home_1 = as.data.frame(data[3])
    colnames(home_1) = c("Players","MP","FG","FGA","FG%","3P","3PA","3P%","FT","FTA",
     "FT%", "ORB","DRB","TRB","AST","STL","BLK","TO","PF","PTS","+/-")

    home_1 = home_1[home_1$Players != "Reserves",]
    home_1 = home_1[home_1$MP != "Did Not Play",]

    home_1$team = rep(toupper(substr(names(as.data.frame(data[2]))[1], 
                            5, 7)),length(home_1$Players))
    home_1$loc = rep(i,length(home_1$Players))

    game = rbind(away_1,home_1)

    october = rbind(october, game)
  }
}

```

Everything above and below the following lines appears to work:

```
data <- try(readHTMLTable(url, stringsAsFactors = FALSE))

if(inherits(data, "error")) next

```

I just need to properly format these two.