Project Overview

The purpose of this assignment is to work with a public New York Times API using R. I will retrieve data through an API request, process the JSON response, and organize the information into a tidy data frame for analysis.

For this assignment, I selected the New York Times Most Popular API, which provides information about articles that receive the most views, shares, or emails during a specific period. I chose this API because it provides structured article information that can be easily processed and analyzed using R.

My main research question is:

Which sections of The New York Times have the most articles appearing on the most-viewed list during the past seven days?

API Overview

I selected the New York Times Most Popular API, which provides information about the most-viewed articles over a specified period.

API Endpoint:

/svc/mostpopular/v2/viewed/7.json

API Base URL:

https://api.nytimes.com

Request Parameters:

The API returns article information in JSON format, including article titles, sections, publication dates, and other metadata.

An API key is required to access the data. For security, I will store my key in an environment variable and retrieve it in R using Sys.getenv("NYT_API_KEY") instead of including it directly in the code.

This approach protects the API key and allows the R code to be shared without exposing authentication credentials.

Methodology

I plan to complete the assignment using the following steps:

Data Cleaning and Preparation

Before analyzing the data, I will review the returned information to identify any missing values, unnecessary columns, or formatting issues.

Some articles may not have a subsection or other optional information. I will keep these missing values as NA unless a specific adjustment is necessary.

The API response may also contain nested information, such as multimedia details. Since my analysis focuses on article sections, I will exclude these fields from the main data frame.

I will also convert publication dates into the correct R date format so they can be used in future analysis if needed.

Finally, I will select only the variables relevant to my research question. Each row in the final data frame will represent one article, and each column will represent a specific article attribute.

Anticipated Results

By completing this assignment, I expect to develop a reproducible R workflow that retrieves data from the New York Times Most Popular API and converts the JSON response into a clean, organized data frame.

I will then summarize the articles by news section to identify which sections appear most frequently among the most-viewed articles during the seven-day period.

This analysis will help me practice working with APIs, handling JSON data, cleaning datasets, and performing basic exploratory analysis using R.

The results will describe the distribution of articles in the API’s most-viewed list rather than measure the total readership of each news section.