knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of nytimes
is to integrate all of the New York Times API with R.
#install.packages("remotes") remotes::install_github("news-r/nytimes")
First, create an account to obtain an API key. Then either specify the aforementioned key using nytimes_key
or specify it as environment variable (likely in your .Renviron
) as NYTIMES_API_KEY
.
library(nytimes) nytimes_key("xXxxX")
The archive API.
library(nytimes) # get all articles from January first 2018 archive <- ny_archive(2018, 1)
The article search API.
# get all articles on Obama that have been published in the last 3 days, get three pages of results obama <- ny_search("Obama", since = Sys.Date() - 3, pages = 3)
The books API
# get data on a random book books <- ny_book_names() list <- ny_book_list(sample(books$list_name_encoded, 1))
The most popular API
# get most viewed articles in the last 7 days viewed <- ny_popular_viewed(7)
The movie review API
# get 2 pages of movie reviews on war reviews <- ny_movie_search("war", pages = 2)
The semantic API
# get 2 pages of movie reviews on war concepts <- ny_semantic_search("war")
Times tags API
ny_tags("Trump", max = 6)
Top stories API
business <- ny_stories("business")
Times wire API
sections <- ny_wire_section_list() wires <- ny_wire_source(sample(sections$section, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.