Skip to content

Instantly share code, notes, and snippets.

Last active Nov 22, 2019
What would you like to do?
# I will try to post a longer handout, but here is the needed code for accessing nytimes.
# See also:
# 1. Install the package from github:
# 2. Get an API key from nytimes
# - create an account at
# - activate the account from your email and log in
# - create a new 'app' (in your username menu) and select article search API
# - record the API key and enter it below:
# 3. Search!
nytsearch <-"sanctions", n = 20))
# To convert to a quanteda dfm:
corp = corpus(nytsearch, docid_field = "id", text_field="lead_paragraph")
dfm = dfm(corp, remove=stopwords("english"), remove_punct=T)
textplot_wordcloud(dfm, max_words=100)
# If you want to convert to tidyverse, first convert date to POSIXct
nytsearch$pub_date = as.POSIXct(nytsearch$pub_date)
nytsearch = as_tibble(nytsearch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment