## 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)
install.packages("devtools")
devtools::install_github("mkearney/nytimes")
## load nytimes package
library(nytimes)
## 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)
## 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)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.