Created
October 16, 2014 21:31
-
-
Save mharris717/6a4ef2f3dd364cde0c88 to your computer and use it in GitHub Desktop.
We must kill the Loop .... Man.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pretending to fetch HTML | |
getBody <- function(url) { | |
if (url == "http://garbage.broken") return(0) | |
else return(paste("this is the html for ",url)) | |
} | |
sites.names <- c("Google","ESPN","Garbage","ROK") | |
sites.urls <- c("http://google.com","http://espn.com","http://garbage.broken","http://returnofkings.com") | |
sites.df <- data.frame(Name=sites.names, Url=sites.urls, stringsAsFactors=FALSE) | |
# I want to get the HTML for the working sites | |
# No loop you guys | |
goodBodies <- Reduce(function(list,url) { | |
body <- getBody(url) | |
if (body != 0) c(list,body) else list | |
},sites.df["Url"][[1]],vector()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment