Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205491

I have an "Error: failed to load external entity" when I try to run the R code

$
0
0

I got the below R code from online and tried to run, but keep getting an error: Error: failed to load external entity "http://www.baseball-reference.com/teams/ARI/1998-schedule-scores.shtml". Any suggestions to fix?

library("XML")

fetch <- function(team, year) {
  url <- paste0("http://www.baseball-reference.com/teams/", team, "/", year, "-schedule-scores.shtml")
  raw <- readHTMLTable(url, stringsAsFactors = FALSE)
  if (ncol(raw[[6]]) == 21) {
data <- raw[[6]]
  } else {
data <- raw[[7]]
  }
  data$year <- year
  data
} 

# 1 - Arizona Diamondbacks
ARI <- rbind(fetch("ARI", 1998), fetch("ARI", 1999), fetch("ARI", 2000), fetch("ARI", 2001), fetch("ARI", 2002), 
         fetch("ARI", 2003), fetch("ARI", 2004), fetch("ARI", 2005), fetch("ARI", 2006), fetch("ARI", 2007), 
         fetch("ARI", 2008), fetch("ARI", 2009), fetch("ARI", 2010), fetch("ARI", 2011), fetch("ARI", 2012), 
         fetch("ARI", 2013), fetch("ARI", 2014))
save(ARI, file="data/raw/ARI.rda")

Viewing all articles
Browse latest Browse all 205491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>