Objective: Connect to NY Times API and extract then formulate
data
# Load necessary libraries
library(httr2)
library(jsonlite)
# Define the API endpoint URL
API_URL <- "https://api.nytimes.com/svc/topstories/v2/world.json?api-key=m2scA9nuAXf7FFHykVAXSbRwnHozhIO2"
# Make a GET request to the API endpoint
api_call <- httr::GET(API_URL)
# Extract the content of the API response
head(api_call$content, 10)
## [1] 7b 22 73 74 61 74 75 73 22 3a
# Convert the raw content to a character string
api_char <- rawToChar(api_call$content)
# Parse the JSON content into a nested list
api_json <- fromJSON(api_char, flatten=TRUE)
# Convert the 'result' part of the JSON response to a data frame
data <- as.data.frame(api_json$result)
head(data, 10)
## section subsection
## 1 world middleeast
## 2 world europe
## 3 world europe
## 4 world europe
## 5 world americas
## 6 world africa
## 7 world europe
## 8 world middleeast
## 9 world europe
## 10
## title
## 1 Witnesses Describe Fear and Deprivation at Besieged Hospital in Gaza
## 2 The Brutality of Sugar: Debt, Child Marriage and Hysterectomies
## 3 Pope Lets Silence Speak for Him as He Skips a Palm Sunday Speech
## 4 In Russia, Fingers Point Anywhere but at ISIS for Concert Hall Attack
## 5 Police Say They’ve Cracked Rio de Janeiro’s Most Notorious Murder Mystery
## 6 Senegal Votes in an Election That Almost Didn’t Happen
## 7 Russia’s Battle With Extremists Has Simmered for Years
## 8 In Hezbollah’s Sights, a Stretch of Northern Israel Becomes a No-Go Zone
## 9 41 Days in a Bunker: How a Battle Raged on Ukraine’s Bloody Front Line
## 10 Moscow Concert Hall Shooting: Security Questions Emerge as First Charges Are Filed in Russia Attack
## abstract
## 1 Several patients have died as a result of the Israeli military assault, the Gazan authorities say. Israel says the operation is targeting Hamas leaders.
## 2 An investigation into the sugar-cane industry in the Indian state of Maharashtra found workers ensnared by debt and pushed into child marriages and unnecessary hysterectomies.
## 3 Pope Francis’ choice to skip the strenuous speech at the outset of Easter week immediately raised concerns about his health, but he spoke in a clear voice before and after it.
## 4 Russian state media pushed the idea that Ukraine was the obvious culprit, but at least three of the four suspects charged on Sunday are from the Central Asian nation of Tajikistan.
## 5 Two politicians were arrested in the assassination of a rival, Marielle Franco, who was known for fighting corruption and police violence.
## 6 The top opposition politician, Ousmane Sonko, is barred from running. So Sunday’s vote is widely seen as a choice between his handpicked candidate and the departing president’s designated successor.
## 7 The Islamic State has long threatened to strike Russia for helping the Syrian president, Bashar al-Assad, stay in control.
## 8 For the few Israelis remaining in the evacuated zone along the northern border with Lebanon, the simmering conflict there has become intensely personal.
## 9 A struggle for a position held by Ukrainian forces in the eastern city of Avdiivka underlines how the conflict is increasingly being fought in close-quarter combat.
## 10 Russian officials formally charged four men in the attack, which killed at least 137 people at a Moscow-area concert hall on Friday. American officials blamed a branch of the Islamic State.
## url
## 1 https://www.nytimes.com/2024/03/24/world/middleeast/al-shifa-hospital-gaza-israel.html
## 2 https://www.nytimes.com/2024/03/24/world/europe/india-sugar-cane-fields-child-labor-hysterectomies.html
## 3 https://www.nytimes.com/2024/03/24/world/europe/pope-francis-palm-sunday-homily.html
## 4 https://www.nytimes.com/2024/03/24/world/europe/russia-moscow-concert-hall-attack.html
## 5 https://www.nytimes.com/2024/03/24/world/americas/brazil-marielle-franco-assassination-arrest.html
## 6 https://www.nytimes.com/2024/03/24/world/africa/senegal-presidential-election.html
## 7 https://www.nytimes.com/2024/03/24/world/europe/russia-extremism-isis-syria.html
## 8 https://www.nytimes.com/2024/03/24/world/middleeast/israel-hezbollah-lebanon-border.html
## 9 https://www.nytimes.com/2024/03/24/world/europe/ukraine-war-avdiivka.html
## 10 https://www.nytimes.com/live/2024/03/24/world/moscow-russia-attack-news
## uri
## 1 nyt://article/0d82ab74-733e-518d-85d9-e56f0f5645c9
## 2 nyt://article/ee0f0cad-2035-5322-8bcc-ea90c6cc4867
## 3 nyt://article/f38928c3-9ff8-5ac8-a1ba-894495cd3d88
## 4 nyt://article/f909c2d4-377e-527d-9d1b-23980d281390
## 5 nyt://article/df186b1c-f7e9-5da8-b486-8cbc45bd6703
## 6 nyt://article/af799cee-5530-508a-9151-4ea8953969ad
## 7 nyt://article/960dfbf6-4349-5c7a-97c4-2cf97d727068
## 8 nyt://article/cdca07a3-9512-5fd1-b1db-c772055c6124
## 9 nyt://article/169e678f-19b8-580f-82fe-db597ffa49de
## 10 nyt://promo/b2a782fb-874c-54d3-a603-89870db2260b
## byline item_type
## 1 By Raja Abdulrahim and Ameera Harouda Article
## 2 By Megha Rajagopalan, Qadri Inzamam and Saumya Khandelwal Article
## 3 By Jason Horowitz Article
## 4 By Ivan Nechepurenko, Paul Sonne and Kayla Guo Article
## 5 By Jack Nicas and Flávia Milhorance Article
## 6 By Ruth Maclean and Mady Camara Article
## 7 By Neil MacFarquhar Article
## 8 By Isabel Kershner and Sergey Ponomarev Article
## 9 By Marc Santora Article
## 10 Promo
## updated_date created_date
## 1 2024-03-24T16:45:24-04:00 2024-03-24T10:44:18-04:00
## 2 2024-03-24T14:30:30-04:00 2024-03-24T00:04:20-04:00
## 3 2024-03-24T09:55:30-04:00 2024-03-24T09:55:30-04:00
## 4 2024-03-24T19:55:00-04:00 2024-03-24T19:37:12-04:00
## 5 2024-03-24T16:13:01-04:00 2024-03-24T12:33:38-04:00
## 6 2024-03-24T13:12:19-04:00 2024-03-24T00:01:45-04:00
## 7 2024-03-24T14:22:32-04:00 2024-03-24T07:03:41-04:00
## 8 2024-03-24T13:35:06-04:00 2024-03-24T05:01:11-04:00
## 9 2024-03-24T00:01:10-04:00 2024-03-24T00:01:10-04:00
## 10 2024-03-24T21:56:08-04:00 2024-03-24T04:14:24-04:00
## published_date material_type_facet kicker
## 1 2024-03-24T10:44:18-04:00
## 2 2024-03-24T00:04:20-04:00
## 3 2024-03-24T09:55:30-04:00
## 4 2024-03-24T19:37:12-04:00
## 5 2024-03-24T12:33:38-04:00
## 6 2024-03-24T00:01:45-04:00
## 7 2024-03-24T07:03:41-04:00
## 8 2024-03-24T05:01:11-04:00
## 9 2024-03-24T00:01:10-04:00
## 10 2024-03-24T04:14:24-04:00
## des_facet
## 1 Hospitals, Civilian Casualties, Palestinians, Defense and Military Forces, Israel-Gaza War (2023- )
## 2 Sugar, Agriculture and Farming, Forced Labor, Child Labor, Human Rights and Human Rights Violations, Women and Girls, Hysterectomies, Supply Chain, Soft Drinks, International Trade and World Market, Child Marriages
## 3 Easter and Holy Week, Popes
## 4 Moscow Concert Hall Shooting (March 2024), Russian Invasion of Ukraine (2022), Conspiracy Theories
## 5 Assassinations and Attempted Assassinations, Police
## 6 Elections, Youth, Politics and Government, Sufism (Religion)
## 7 Terrorism, Muslims and Islam, Moscow Concert Hall Shooting (March 2024)
## 8 Israel-Gaza War (2023- )
## 9 Russian Invasion of Ukraine (2022), Defense and Military Forces
## 10
## org_facet
## 1 Al Shifa Hospital (Gaza Strip)
## 2 NSL Sugars Ltd, Dalmia Bharat Sugar and Industries Ltd, Coca-Cola Company, Pepsico Inc
## 3 Roman Catholic Church
## 4 Islamic State Khorasan, Investigative Committee (Russia)
## 5 Supreme Federal Court (Brazil)
## 6
## 7 Islamic State in Iraq and Syria (ISIS)
## 8 Hezbollah
## 9
## 10
## per_facet
## 1
## 2
## 3 Francis
## 4 Putin, Vladimir V
## 5 Franco, Marielle (1979-2018), Lessa, Ronnie
## 6 Sall, Macky, Sonko, Ousmane, Ba, Amadou (1961- ), Faye, Bassirou Diomaye
## 7 Assad, Bashar al-
## 8
## 9
## 10
## geo_facet
## 1 Israel, Gaza Strip
## 2 Maharashtra (India), India
## 3 Rome (Italy)
## 4 Moscow (Russia), Russia, Ukraine
## 5 Brazil, Rio de Janeiro (Brazil)
## 6 Senegal, Africa
## 7 Afghanistan, Chechnya (Russia), Moscow (Russia)
## 8 Israel, Lebanon, Kiryat Shmona (Israel)
## 9 Avdiivka (Ukraine), Ukraine
## 10
## multimedia
## 1 https://static01.nyt.com/images/2024/03/24/multimedia/24mideast-shifa-01-zjmg/24mideast-shifa-01-zjmg-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24mideast-shifa-01-zjmg/24mideast-shifa-01-zjmg-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24mideast-shifa-01-zjmg/24mideast-shifa-01-zjmg-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1366, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, A young Palestinian man awaiting medical attention at Al-Shifa Hospital in Gaza City this month. Israel’s assault on the complex has been one of the longest hospital raids of the war., A young Palestinian man awaiting medical attention at Al-Shifa Hospital in Gaza City this month. Israel’s assault on the complex has been one of the longest hospital raids of the war., A young Palestinian man awaiting medical attention at Al-Shifa Hospital in Gaza City this month. Israel’s assault on the complex has been one of the longest hospital raids of the war., Agence France-Presse — Getty Images, Agence France-Presse — Getty Images, Agence France-Presse — Getty Images
## 2 https://static01.nyt.com/images/2024/03/05/multimedia/00india-sugar-04-pjvt/00india-sugar-04-pjvt-superJumbo.jpg, https://static01.nyt.com/images/2024/03/05/multimedia/00india-sugar-04-pjvt/00india-sugar-04-pjvt-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/05/multimedia/00india-sugar-04-pjvt/00india-sugar-04-pjvt-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1367, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Workers in a cane field near NSL Sugars in the Beed district of Maharashtra, India, last year. Mills pay contractors to employ field workers., Workers in a cane field near NSL Sugars in the Beed district of Maharashtra, India, last year. Mills pay contractors to employ field workers., Workers in a cane field near NSL Sugars in the Beed district of Maharashtra, India, last year. Mills pay contractors to employ field workers., , ,
## 3 https://static01.nyt.com/images/2024/03/24/multimedia/24pope-02-vftc/24pope-02-vftc-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24pope-02-vftc/24pope-02-vftc-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24pope-02-vftc/24pope-02-vftc-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Pope Francis celebrating the Palm Sunday Mass on Sunday in St. Peter’s Square at the Vatican., Pope Francis celebrating the Palm Sunday Mass on Sunday in St. Peter’s Square at the Vatican., Pope Francis celebrating the Palm Sunday Mass on Sunday in St. Peter’s Square at the Vatican., Alessandra Tarantino/Associated Press, Alessandra Tarantino/Associated Press, Alessandra Tarantino/Associated Press
## 4 https://static01.nyt.com/images/2024/03/24/multimedia/24moscow-attack-ledeall-qzhk/24moscow-attack-ledeall-qzhk-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24moscow-attack-ledeall-qzhk/24moscow-attack-ledeall-qzhk-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24moscow-attack-ledeall-qzhk/24moscow-attack-ledeall-qzhk-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1537, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Scores of people brought flowers to a memorial at Crocus City Hall, where the attack took place, on Sunday., Scores of people brought flowers to a memorial at Crocus City Hall, where the attack took place, on Sunday., Scores of people brought flowers to a memorial at Crocus City Hall, where the attack took place, on Sunday., Nanna Heitmann for The New York Times, Nanna Heitmann for The New York Times, Nanna Heitmann for The New York Times
## 5 https://static01.nyt.com/images/2024/03/24/multimedia/24brazil-arrests-01-wkjf/24brazil-arrests-01-wkjf-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24brazil-arrests-01-wkjf/24brazil-arrests-01-wkjf-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24brazil-arrests-01-wkjf/24brazil-arrests-01-wkjf-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1399, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Marielle Franco, who was killed in 2018, was one of Brazil’s rising political stars and had battled corruption and gangs in Rio de Janeiro., Marielle Franco, who was killed in 2018, was one of Brazil’s rising political stars and had battled corruption and gangs in Rio de Janeiro., Marielle Franco, who was killed in 2018, was one of Brazil’s rising political stars and had battled corruption and gangs in Rio de Janeiro., Ellis Rua/Associated Press, Ellis Rua/Associated Press, Ellis Rua/Associated Press
## 6 https://static01.nyt.com/images/2024/03/24/multimedia/24senegal-election-bcwh/24senegal-election-bcwh-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24senegal-election-bcwh/24senegal-election-bcwh-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24senegal-election-bcwh/24senegal-election-bcwh-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1366, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Voting on Sunday in Ziguinchor, Senegal, in an election that many young people see as a chance to overhaul the political and economic order., Voting on Sunday in Ziguinchor, Senegal, in an election that many young people see as a chance to overhaul the political and economic order., Voting on Sunday in Ziguinchor, Senegal, in an election that many young people see as a chance to overhaul the political and economic order., Muhamadou Bittaye/Agence France-Presse — Getty Images, Muhamadou Bittaye/Agence France-Presse — Getty Images, Muhamadou Bittaye/Agence France-Presse — Getty Images
## 7 https://static01.nyt.com/images/2024/03/24/multimedia/24russia-extremism-jkqb/24russia-extremism-jkqb-superJumbo.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24russia-extremism-jkqb/24russia-extremism-jkqb-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24russia-extremism-jkqb/24russia-extremism-jkqb-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1536, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, A makeshift memorial on Saturday for the victims of the Crocus City Hall concert attack in Moscow., A makeshift memorial on Saturday for the victims of the Crocus City Hall concert attack in Moscow., A makeshift memorial on Saturday for the victims of the Crocus City Hall concert attack in Moscow., Nanna Heitmann for The New York Times, Nanna Heitmann for The New York Times, Nanna Heitmann for The New York Times
## 8 https://static01.nyt.com/images/2024/03/17/multimedia/17israel-north-01-whlz-promo/17israel-north-01-whlz-superJumbo.jpg, https://static01.nyt.com/images/2024/03/17/multimedia/17israel-north-01-whlz-promo/17israel-north-01-whlz-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/17/multimedia/17israel-north-01-whlz-promo/17israel-north-01-whlz-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, A building in Kiryat Shmona, a city near Israel’s northern border with Lebanon, was damaged in an attack by Hezbollah, the Lebanese militant group., A building in Kiryat Shmona, a city near Israel’s northern border with Lebanon, was damaged in an attack by Hezbollah, the Lebanese militant group., A building in Kiryat Shmona, a city near Israel’s northern border with Lebanon, was damaged in an attack by Hezbollah, the Lebanese militant group., Sergey Ponomarev for The New York Times, Sergey Ponomarev for The New York Times, Sergey Ponomarev for The New York Times
## 9 https://static01.nyt.com/images/2024/03/23/multimedia/23ukraine-avdiivka-dispatch-01-pqtg/23ukraine-avdiivka-dispatch-01-pqtg-superJumbo.jpg, https://static01.nyt.com/images/2024/03/23/multimedia/23ukraine-avdiivka-dispatch-01-pqtg/23ukraine-avdiivka-dispatch-01-pqtg-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2024/03/23/multimedia/23ukraine-avdiivka-dispatch-01-pqtg/23ukraine-avdiivka-dispatch-01-pqtg-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Ukrainian Army soldiers firing at Russian targets in the direction of Avdiivka in February., Ukrainian Army soldiers firing at Russian targets in the direction of Avdiivka in February., Ukrainian Army soldiers firing at Russian targets in the direction of Avdiivka in February., Tyler Hicks/The New York Times, Tyler Hicks/The New York Times, Tyler Hicks/The New York Times
## 10 https://static01.nyt.com/images/2024/03/24/multimedia/24russia-live-suspects-8pm/24russia-live-suspects-6pm-superJumbo-v2.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24russia-live-suspects-8pm/24russia-live-suspects-6pm-threeByTwoSmallAt2X-v2.jpg, https://static01.nyt.com/images/2024/03/24/multimedia/24russia-live-suspects-8pm/24russia-live-suspects-6pm-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1366, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, , , , Shamil Zhumatov/Reuters, Shamil Zhumatov/Reuters, Shamil Zhumatov/Reuters
## short_url
## 1
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9
## 10