Skip to content

Instantly share code, notes, and snippets.

@expersso
Last active June 10, 2016 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expersso/622ad627325f834588252b28599dcee6 to your computer and use it in GitHub Desktop.
Save expersso/622ad627325f834588252b28599dcee6 to your computer and use it in GitHub Desktop.
Get locations of Federal Reserve Speeches
library(purrr)
library(dplyr)
library(rvest)
library(stringr)
library(geoparser)
w_msg <- function(f) {
force(f)
function(...) {
args <- list(...)
message("Processing: ", args[[1]])
f(...)
}
}
sample_vec <- function(x, n = 5) {
x[sample(length(x), n)]
}
get_fed_location <- function(year) {
"http://www.federalreserve.gov/newsevents/speech/%sspeech.htm" %>%
sprintf(year) %>%
read_html() %>%
html_nodes(xpath = "//div[@class = 'location']") %>%
xml_text()
}
locations <- 1996:2016 %>%
map(get_fed_location) %>%
flatten_chr() %>%
str_trim()
geo_data <- locations %>%
sample_vec(3) %>%
map(w_msg(geoparser_q)) %>%
transpose() %>%
.$results %>%
rbind_all()
geo_data
# Processing: At the Federal Reserve Bank of Kansas City's Annual Economic Symposium, Jackson Hole, Wyoming
# Processing: At New Approaches to Rural Policy: Lessons from Around the World, an international conference convened by the Federal Reserve Bank of Kansas City, Organization for Economic Cooperation and Development (OECD), Rural Policy Research Institute, and The Countryside Agency, Warrenton, Virginia
# Processing: At the Federal Reserve System<U+0092>s Conference on Implementing an Advanced Measurement Approach for Operational Risk, Boston, Massachusetts
# Source: local data frame [5 x 10]
#
# country confidence name admin1 type geometry.type longitude latitude reference1
# (fctr) (fctr) (chr) (chr) (chr) (fctr) (dbl) (dbl) (dbl)
# 1 US 1 Wyoming MI populated place Point -85.70531 42.91336 86
# 2 US 1 Warrenton VA seat of a second-order administrative division Point -77.79527 38.71345 270
# 3 US 1 Virginia VA first-order administrative division Point -77.44675 37.54812 281
# 4 US 1 Massachusetts MA first-order administrative division Point -71.10832 42.36565 122
# 5 US 1 Boston MA seat of a first-order administrative division Point -71.05977 42.35843 114
# Variables not shown: reference2 (dbl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment