# Article Search API endpoint
endpoint <- "https://api.nytimes.com/svc/search/v2/articlesearch.json"New York Times Coverage of Girls’ Education in Afghanistan
Introduction
This project investigates the following research question:
How has The New York Times covered girls’ education in Afghanistan from August 2021 to August 2026?
I will use the New York Times Article Search API to collect article metadata published between August 1, 2021, and August 31, 2026. I will examine publication patterns over time and review article headlines and summaries to understand the topics covered.
The data source is the New York Times Article Search API.
Project Objective
The objective of this project is to analyze The New York Times’ coverage of girls’ education in Afghanistan between August 1, 2021, and August 31, 2026, using the New York Times Article Search API.
The analysis will examine the number of relevant articles published each year, their headlines, publication dates, news sections, and summaries. It will also explore changes in the frequency of coverage over the selected period.
API Selection and Request Parameters
The selected endpoint is:
The Article Search API searches New York Times articles by keywords and returns metadata in JSON format.
The request uses these parameters:
api-key: API authentication key stored in an environment variable.
q: Search terms related to girls’ education in Afghanistan.
begin_date: August 1, 2021 (20210801). end_date: August 31, 2026 (20260831). sort: Publication date, newest first. page: Page number used to retrieve additional results.
Multiple search queries will be used to reduce dependence on a single phrase. The results will subsequently be combined and deduplicated.
Load Packages and Authenticate
library(httr2)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(purrr)
library(tibble)
library(stringr)
library(lubridate)
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
library(knitr)
library(rlang)
Attaching package: 'rlang'
The following objects are masked from 'package:purrr':
flatten, flatten_chr, flatten_dbl, flatten_int, flatten_lgl,
flatten_raw, invoke, splice
##Authentication
api_key <- Sys.getenv("NYT_API_KEY")
if (api_key == "") {
stop("API key not found. Please check your .Renviron file.")
}
print("API key loaded successfully.")[1] "API key loaded successfully."
start_date <- "20210801"
end_date <- "20260831"test_response <- httr2::request(endpoint) |>
httr2::req_url_query(
`api-key` = api_key,
q = "Afghanistan girls education",
begin_date = start_date,
end_date = end_date
) |>
httr2::req_perform()
httr2::resp_check_status(test_response)
print("NYT API connection successful!")[1] "NYT API connection successful!"
get_nyt_page <- function(query, page_number, api_key) {
request <- httr2::request(endpoint) |>
httr2::req_url_query(
`api-key` = api_key,
q = query,
begin_date = start_date,
end_date = end_date,
sort = "newest",
page = page_number
) |>
httr2::req_timeout(30)
response <- httr2::req_perform(request)
httr2::resp_check_status(response)
httr2::resp_body_json(
response,
simplifyVector = FALSE
)
}search_queries <- c(
"Afghanistan girls education",
"Afghan girls school"
)
pages <- map(search_queries, function(query) {
# Wait 15 seconds before each API request
Sys.sleep(15)
result <- get_nyt_page(query, 0, api_key)
list(
search_query = query,
data = result
)
})
article_records <- map(pages, function(page_result) {
records <- page_result$data$response$docs
if (length(records) == 0) {
return(tibble())
}
map_dfr(records, function(article) {
tibble(
article_id = article$`_id` %||% NA_character_,
headline = article$headline$main %||% NA_character_,
abstract = article$abstract %||% NA_character_,
snippet = article$snippet %||% NA_character_,
publication_date = article$pub_date %||% NA_character_,
section = article$section_name %||% NA_character_,
news_desk = article$news_desk %||% NA_character_,
url = article$web_url %||% NA_character_,
search_query = page_result$search_query
)
})
})
nyt_raw <- bind_rows(article_records)
nrow(nyt_raw)[1] 20
nyt_articles <- nyt_raw |>
mutate(
publication_date = as.Date(
substr(publication_date, 1, 10)
)
) |>
filter(
!is.na(publication_date),
publication_date >= as.Date("2021-08-01"),
publication_date <= as.Date("2026-08-31")
) |>
mutate(
headline = na_if(str_squish(headline), ""),
abstract = na_if(str_squish(abstract), ""),
section = na_if(str_squish(section), ""),
url = na_if(str_squish(url), "")
) |>
filter(!is.na(headline)) |>
distinct(article_id, .keep_all = TRUE) |>
mutate(
year = lubridate::year(publication_date)
) |>
select(
article_id,
headline,
abstract,
snippet,
publication_date,
year,
section,
news_desk,
url,
search_query
)
knitr::kable(
nyt_articles,
caption = "All Retrieved New York Times Articles"
)| article_id | headline | abstract | snippet | publication_date | year | section | news_desk | url | search_query |
|---|---|---|---|---|---|---|---|---|---|
| nyt://article/691d9d58-d229-543f-b5fa-c5d4a9bee7a4 | Melting Himalayas | Scientists are still working out the precise cause of the disaster in Nepal, but one thing seems certain: The risk of such events is increasing. | Scientists are still working out the precise cause of the disaster in Nepal, but one thing seems certain: The risk of such events is increasing. | 2026-08-30 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/30/world/nepal-tibet-flood-glacier-nasa.html | Afghanistan girls education |
| nyt://article/b4134558-6801-570c-9edc-81610f2c7505 | Nepal Roughly Doubles Number of Missing After Flood | Also, Trump orders the creation of a space academy. Here’s the latest at the end of Friday. | Also, Trump orders the creation of a space academy. Here’s the latest at the end of Friday. | 2026-08-28 | 2026 | Briefing | NYTNow | https://www.nytimes.com/2026/08/28/briefing/nepal-flood-missing-trump-space-academy.html | Afghanistan girls education |
| nyt://article/fba3286e-5f67-5b07-866a-73cf63700cbb | Inside Afghanistan’s Secret Schools for Girls | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | 2026-08-28 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/28/world/asia/afghanistan-girls-education.html | Afghanistan girls education |
| nyt://article/e0773cce-22fe-5fd3-ab1c-a86e2fb7e7c3 | A Bitter Anniversary for Afghan Women | Readers respond to a guest essay about the U.S. failure in Afghanistan and the Taliban’s oppression of women. Also: the use of A.I. in medicine. | Readers respond to a guest essay about the U.S. failure in Afghanistan and the Taliban’s oppression of women. Also: the use of A.I. in medicine. | 2026-08-18 | 2026 | Opinion | Letters | https://www.nytimes.com/2026/08/18/opinion/afghanistan-taliban-women.html | Afghanistan girls education |
| nyt://article/939e3820-f7d4-5ab8-a0df-d795d69367d6 | Entrenched, Embattled and Defiant, the Taliban Celebrate 5 Years in Power | The Taliban have Afghanistan in a chokehold that spares no one. But threats are starting to crack their veneer of stability and control. | The Taliban have Afghanistan in a chokehold that spares no one. But threats are starting to crack their veneer of stability and control. | 2026-08-15 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/15/world/asia/entrenched-embattled-and-defiant-the-taliban-celebrate-5-years-in-power.html | Afghanistan girls education |
| nyt://article/6f86e7d9-b10d-50da-a87d-4ca2c395c94b | The Taliban Kicked the U.S. Out of Afghanistan. Now They Want It Back. | In an interview, Afghanistan’s foreign minister called on the U.S. to reopen its embassy and invest in the country — a near-impossible sell for now, analysts and former diplomats say. | In an interview, Afghanistan’s foreign minister called on the U.S. to reopen its embassy and invest in the country — a near-impossible sell for now, analysts and former diplomats say. | 2026-08-14 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/14/world/asia/afghanistan-us-taliban.html | Afghanistan girls education |
| nyt://article/d3a1a41e-8a26-589d-8dfc-282fd68d371e | U.S. Policy on Afghanistan Is a Relic of the Past | A new generation of Afghans wants to move on from the animosities of the past, but Western policies make that difficult. | A new generation of Afghans wants to move on from the animosities of the past, but Western policies make that difficult. | 2026-08-14 | 2026 | Opinion | OpEd | https://www.nytimes.com/2026/08/14/opinion/afghanistan-us-anniversary-kabul-five-years.html | Afghanistan girls education |
| nyt://article/f4fdaef2-c0a7-5af2-ac84-53455a20c13d | Afghan Women Erased From Public Life in Five Years of Taliban Rule | Decrees restricting the rights of women and girls to study, work, travel and act independently now threaten to damage Afghanistan permanently, experts say. | Decrees restricting the rights of women and girls to study, work, travel and act independently now threaten to damage Afghanistan permanently, experts say. | 2026-08-13 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/13/world/asia/afghan-women-taliban-rule.html | Afghanistan girls education |
| nyt://article/19241b58-b544-5822-8a0c-f52920278b57 | Afghanistan’s Unhappy Anniversary | Five years into their hard-line rule, the Taliban find themselves in crisis at home and abroad. | Five years into their hard-line rule, the Taliban find themselves in crisis at home and abroad. | 2026-08-12 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/12/world/afghanistan-taliban-anniversary-eclipse-lakers.html | Afghanistan girls education |
| nyt://article/353cf8fb-ad00-5a36-b9ca-1140c46d65dc | What America Owes to Afghan Women | Five years after giving up on Afghanistan, America still has a responsibility to the country’s women. | Five years after giving up on Afghanistan, America still has a responsibility to the country’s women. | 2026-08-10 | 2026 | Opinion | OpEd | https://www.nytimes.com/2026/08/10/opinion/afghanistan-women-america.html | Afghanistan girls education |
| nyt://article/6f191392-ab95-5f08-b50d-c3a2dc4aa6d0 | This Marine Died in the Iraq War. His Mother Asks, ‘What Was It For?’ | Travis Fuller was from my hometown. I went back and talked with his family about how they made sense of his death, 25 years after Sept. 11. | Travis Fuller was from my hometown. I went back and talked with his family about how they made sense of his death, 25 years after Sept. 11. | 2026-08-31 | 2026 | U.S. | National | https://www.nytimes.com/2026/08/31/us/politics/iraq-war-marine-death.html | Afghan girls school |
| nyt://article/97e9928c-1c66-5cc8-a327-7b62f03baab4 | Bot Meets Bot | Are we ready for a world where machines are mostly talking to each other? | Are we ready for a world where machines are mostly talking to each other? | 2026-08-16 | 2026 | Briefing | NYTNow | https://www.nytimes.com/2026/08/16/briefing/chatbots-talking-to-each-other.html | Afghan girls school |
nyt_review <- nyt_articles |>
mutate(
review_text = str_to_lower(
paste(
coalesce(headline, ""),
coalesce(abstract, ""),
coalesce(snippet, "")
)
),
possible_relevance = str_detect(
review_text,
"girl|girls|female|women|education|school|student|university"
) &
str_detect(
review_text,
"afghan|afghanistan"
)
)
knitr::kable(
nyt_review |>
select(
headline,
publication_date,
abstract,
possible_relevance,
url
),
caption = "Initial Relevance Review of NYT Articles"
)| headline | publication_date | abstract | possible_relevance | url |
|---|---|---|---|---|
| Melting Himalayas | 2026-08-30 | Scientists are still working out the precise cause of the disaster in Nepal, but one thing seems certain: The risk of such events is increasing. | FALSE | https://www.nytimes.com/2026/08/30/world/nepal-tibet-flood-glacier-nasa.html |
| Nepal Roughly Doubles Number of Missing After Flood | 2026-08-28 | Also, Trump orders the creation of a space academy. Here’s the latest at the end of Friday. | FALSE | https://www.nytimes.com/2026/08/28/briefing/nepal-flood-missing-trump-space-academy.html |
| Inside Afghanistan’s Secret Schools for Girls | 2026-08-28 | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | TRUE | https://www.nytimes.com/2026/08/28/world/asia/afghanistan-girls-education.html |
| A Bitter Anniversary for Afghan Women | 2026-08-18 | Readers respond to a guest essay about the U.S. failure in Afghanistan and the Taliban’s oppression of women. Also: the use of A.I. in medicine. | TRUE | https://www.nytimes.com/2026/08/18/opinion/afghanistan-taliban-women.html |
| Entrenched, Embattled and Defiant, the Taliban Celebrate 5 Years in Power | 2026-08-15 | The Taliban have Afghanistan in a chokehold that spares no one. But threats are starting to crack their veneer of stability and control. | FALSE | https://www.nytimes.com/2026/08/15/world/asia/entrenched-embattled-and-defiant-the-taliban-celebrate-5-years-in-power.html |
| The Taliban Kicked the U.S. Out of Afghanistan. Now They Want It Back. | 2026-08-14 | In an interview, Afghanistan’s foreign minister called on the U.S. to reopen its embassy and invest in the country — a near-impossible sell for now, analysts and former diplomats say. | FALSE | https://www.nytimes.com/2026/08/14/world/asia/afghanistan-us-taliban.html |
| U.S. Policy on Afghanistan Is a Relic of the Past | 2026-08-14 | A new generation of Afghans wants to move on from the animosities of the past, but Western policies make that difficult. | FALSE | https://www.nytimes.com/2026/08/14/opinion/afghanistan-us-anniversary-kabul-five-years.html |
| Afghan Women Erased From Public Life in Five Years of Taliban Rule | 2026-08-13 | Decrees restricting the rights of women and girls to study, work, travel and act independently now threaten to damage Afghanistan permanently, experts say. | TRUE | https://www.nytimes.com/2026/08/13/world/asia/afghan-women-taliban-rule.html |
| Afghanistan’s Unhappy Anniversary | 2026-08-12 | Five years into their hard-line rule, the Taliban find themselves in crisis at home and abroad. | FALSE | https://www.nytimes.com/2026/08/12/world/afghanistan-taliban-anniversary-eclipse-lakers.html |
| What America Owes to Afghan Women | 2026-08-10 | Five years after giving up on Afghanistan, America still has a responsibility to the country’s women. | TRUE | https://www.nytimes.com/2026/08/10/opinion/afghanistan-women-america.html |
| This Marine Died in the Iraq War. His Mother Asks, ‘What Was It For?’ | 2026-08-31 | Travis Fuller was from my hometown. I went back and talked with his family about how they made sense of his death, 25 years after Sept. 11. | FALSE | https://www.nytimes.com/2026/08/31/us/politics/iraq-war-marine-death.html |
| Bot Meets Bot | 2026-08-16 | Are we ready for a world where machines are mostly talking to each other? | FALSE | https://www.nytimes.com/2026/08/16/briefing/chatbots-talking-to-each-other.html |
Data Cleaning and Preparation
The retrieved data will be cleaned and prepared for analysis. This process includes converting publication dates into the correct format, removing duplicate records, handling missing values, and organizing the article information into a structured dataset.
nyt_articles <- nyt_raw |>
mutate(
publication_date = as.Date(
substr(publication_date, 1, 10)
)
) |>
filter(
!is.na(publication_date),
publication_date >= as.Date("2021-08-01"),
publication_date <= as.Date("2026-08-31")
) |>
mutate(
headline = na_if(str_squish(headline), ""),
abstract = na_if(str_squish(abstract), ""),
section = na_if(str_squish(section), ""),
url = na_if(str_squish(url), "")
) |>
filter(!is.na(headline)) |>
distinct(article_id, .keep_all = TRUE) |>
mutate(
year = lubridate::year(publication_date)
) |>
select(
article_id,
headline,
abstract,
snippet,
publication_date,
year,
section,
news_desk,
url,
search_query
)knitr::kable(
head(nyt_articles, 10),
caption = "First 10 Cleaned New York Times Articles"
)| article_id | headline | abstract | snippet | publication_date | year | section | news_desk | url | search_query |
|---|---|---|---|---|---|---|---|---|---|
| nyt://article/691d9d58-d229-543f-b5fa-c5d4a9bee7a4 | Melting Himalayas | Scientists are still working out the precise cause of the disaster in Nepal, but one thing seems certain: The risk of such events is increasing. | Scientists are still working out the precise cause of the disaster in Nepal, but one thing seems certain: The risk of such events is increasing. | 2026-08-30 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/30/world/nepal-tibet-flood-glacier-nasa.html | Afghanistan girls education |
| nyt://article/b4134558-6801-570c-9edc-81610f2c7505 | Nepal Roughly Doubles Number of Missing After Flood | Also, Trump orders the creation of a space academy. Here’s the latest at the end of Friday. | Also, Trump orders the creation of a space academy. Here’s the latest at the end of Friday. | 2026-08-28 | 2026 | Briefing | NYTNow | https://www.nytimes.com/2026/08/28/briefing/nepal-flood-missing-trump-space-academy.html | Afghanistan girls education |
| nyt://article/fba3286e-5f67-5b07-866a-73cf63700cbb | Inside Afghanistan’s Secret Schools for Girls | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | 2026-08-28 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/28/world/asia/afghanistan-girls-education.html | Afghanistan girls education |
| nyt://article/e0773cce-22fe-5fd3-ab1c-a86e2fb7e7c3 | A Bitter Anniversary for Afghan Women | Readers respond to a guest essay about the U.S. failure in Afghanistan and the Taliban’s oppression of women. Also: the use of A.I. in medicine. | Readers respond to a guest essay about the U.S. failure in Afghanistan and the Taliban’s oppression of women. Also: the use of A.I. in medicine. | 2026-08-18 | 2026 | Opinion | Letters | https://www.nytimes.com/2026/08/18/opinion/afghanistan-taliban-women.html | Afghanistan girls education |
| nyt://article/939e3820-f7d4-5ab8-a0df-d795d69367d6 | Entrenched, Embattled and Defiant, the Taliban Celebrate 5 Years in Power | The Taliban have Afghanistan in a chokehold that spares no one. But threats are starting to crack their veneer of stability and control. | The Taliban have Afghanistan in a chokehold that spares no one. But threats are starting to crack their veneer of stability and control. | 2026-08-15 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/15/world/asia/entrenched-embattled-and-defiant-the-taliban-celebrate-5-years-in-power.html | Afghanistan girls education |
| nyt://article/6f86e7d9-b10d-50da-a87d-4ca2c395c94b | The Taliban Kicked the U.S. Out of Afghanistan. Now They Want It Back. | In an interview, Afghanistan’s foreign minister called on the U.S. to reopen its embassy and invest in the country — a near-impossible sell for now, analysts and former diplomats say. | In an interview, Afghanistan’s foreign minister called on the U.S. to reopen its embassy and invest in the country — a near-impossible sell for now, analysts and former diplomats say. | 2026-08-14 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/14/world/asia/afghanistan-us-taliban.html | Afghanistan girls education |
| nyt://article/d3a1a41e-8a26-589d-8dfc-282fd68d371e | U.S. Policy on Afghanistan Is a Relic of the Past | A new generation of Afghans wants to move on from the animosities of the past, but Western policies make that difficult. | A new generation of Afghans wants to move on from the animosities of the past, but Western policies make that difficult. | 2026-08-14 | 2026 | Opinion | OpEd | https://www.nytimes.com/2026/08/14/opinion/afghanistan-us-anniversary-kabul-five-years.html | Afghanistan girls education |
| nyt://article/f4fdaef2-c0a7-5af2-ac84-53455a20c13d | Afghan Women Erased From Public Life in Five Years of Taliban Rule | Decrees restricting the rights of women and girls to study, work, travel and act independently now threaten to damage Afghanistan permanently, experts say. | Decrees restricting the rights of women and girls to study, work, travel and act independently now threaten to damage Afghanistan permanently, experts say. | 2026-08-13 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/13/world/asia/afghan-women-taliban-rule.html | Afghanistan girls education |
| nyt://article/19241b58-b544-5822-8a0c-f52920278b57 | Afghanistan’s Unhappy Anniversary | Five years into their hard-line rule, the Taliban find themselves in crisis at home and abroad. | Five years into their hard-line rule, the Taliban find themselves in crisis at home and abroad. | 2026-08-12 | 2026 | World | Foreign | https://www.nytimes.com/2026/08/12/world/afghanistan-taliban-anniversary-eclipse-lakers.html | Afghanistan girls education |
| nyt://article/353cf8fb-ad00-5a36-b9ca-1140c46d65dc | What America Owes to Afghan Women | Five years after giving up on Afghanistan, America still has a responsibility to the country’s women. | Five years after giving up on Afghanistan, America still has a responsibility to the country’s women. | 2026-08-10 | 2026 | Opinion | OpEd | https://www.nytimes.com/2026/08/10/opinion/afghanistan-women-america.html | Afghanistan girls education |
# Check the number of cleaned articles
nrow(nyt_articles)[1] 12
# Check missing values in each column
colSums(is.na(nyt_articles)) article_id headline abstract snippet
0 0 0 0
publication_date year section news_desk
0 0 0 0
url search_query
0 0
# Check the publication years
table(nyt_articles$year)
2026
12
Article Relevance Review
The retrieved articles will be reviewed to identify those relevant to the research question. An initial keyword search will identify articles mentioning Afghanistan, girls, and education-related topics. The selected articles will then be manually reviewed using their headlines and summaries to determine their relevance.
nyt_review <- nyt_articles |>
mutate(
review_text = str_to_lower(
paste(
coalesce(headline, ""),
coalesce(abstract, ""),
coalesce(snippet, "")
)
),
possible_relevance =
str_detect(
review_text,
"girl|girls|female"
) &
str_detect(
review_text,
"education|school|student|university|learning"
) &
str_detect(
review_text,
"afghan|afghanistan"
)
)relevant_candidates <- nyt_review |>
filter(possible_relevance == TRUE) |>
select(
headline,
publication_date,
abstract,
section,
url
)
knitr::kable(
relevant_candidates,
caption = "Articles Identified for Manual Relevance Review"
)| headline | publication_date | abstract | section | url |
|---|---|---|---|---|
| Inside Afghanistan’s Secret Schools for Girls | 2026-08-28 | The Taliban have banned education for millions of Afghan girls. Times journalists examined classrooms where students, teachers and parents continue to resist by defying the rules. | World | https://www.nytimes.com/2026/08/28/world/asia/afghanistan-girls-education.html |
nyt_review <- nyt_review |>
mutate(
manual_relevance = NA_character_
)final_articles <- nyt_review |>
filter(manual_relevance == "Yes")
knitr::kable(
final_articles |>
select(
headline,
publication_date,
year,
abstract,
section,
url
),
caption = "Final Relevant New York Times Articles"
)| headline | publication_date | year | abstract | section | url |
|---|