nytimes: Interacting with New York TImes APIs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R fixed Feb 16, 2017
data update readme Aug 4, 2018
man rm ds_store Aug 2, 2018
.Rbuildignore update readme Aug 4, 2018
.gitignore update readme Aug 4, 2018
DESCRIPTION sys.sleep and documentation Feb 16, 2017
LICENSE description license docs Feb 10, 2017
NAMESPACE added sekeltons for other apis Feb 13, 2017
README.Rmd update readme Aug 4, 2018
README.md update readme Aug 4, 2018
nytimes.Rproj add proj files and edit gitignore Apr 16, 2018

README.md

nytimes

lifecycle

  • R functions for accessing New York Times’ APIs
  • Functionality currently extends to “article search”, “most popular”, and “Times newswire” APIs.

Authorizing API access

## replace x's with nytimes article search API key which
##    you can acquire by visiting the following URL:
##    https://developer.nytimes.com/signup
apikey <- paste0("NYTIMES_KEY=", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx")

## make path to .Renviron
file <- file.path(path.expand("~"), ".Renviron")

## save environment variable
cat(apikey, file = file, append = TRUE, fill = TRUE)

Using nytimes package

Install package

install.packages("devtools")
devtools::install_github("mkearney/nytimes")

Load package

## load nytimes package
library(nytimes)

Examples

Article Search API

## get http response objects for search about sanctions
nytsearch <- nyt_search("sanctions", n = 2000)

## convert response object to data frame
nytsearchdf <- as.data.frame(nytsearch)

## preview data
head(nytsearchdf, 10)

Most Popular API

## get data for most popular stories
nytpop <- nyt_mostpopular(metric = "mostshared",
                          section = "U.S.")

## convert response object to data frame
nytpopdf <- as.data.frame(nytpop)

## preview data
head(nytpopdf)

## get media for each observation
get_media(nytpopdf)

Times Newswire API

## get data from the Times newswire
nytwire <- nyt_timeswire(src = "all",
                         section = "all")

## convert response object to data frame
nytwiredf <- as.data.frame(nytwire)

## preview data
head(nytwiredf)

About

  • These functions were created during the Big Dynamic Data working group sponsored by the Center for Research Methods & Data Analysis at the University of Kansas.