Our task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it to an R dataframe.
if (!require('jsonlite')) install.packages('jsonlite')
if (!require('dplyr')) install.packages('dplyr')
if (!require('stringr')) install.packages('stringr')
We will be using Top Stories V1 API and look for stories in the Technology section.
I stored API developer Key in a .R file and sourced accordingly in the code. This file won’t be checked in to the git repository
# get our API key
source("key.R")
# add text required for call
addkey <- paste0("&api-key=", key)
Get call to the API endpoint and get the feed
# add url and text required for call
url <- "https://api.nytimes.com/svc/topstories/v1/technology.json"
addurl <- paste0(url, "?")
# make call
feed <- fromJSON(paste0(addurl, addkey))
sub <- feed$results
sub$pub_date <- unlist(str_extract(sub$published_date, ".+?(?=T)"))
sub$pub_time <- unlist(str_extract(sub$published_date, "(?<=T)(.*)"))
sub <- sub %>%
filter(section == "Technology") %>%
select(title, abstract, byline, url, pub_date, pub_time)
knitr::kable(sub)
| title | abstract | byline | url | pub_date | pub_time |
|---|---|---|---|---|---|
| Clearing Out the App Stores: Government Censorship Made Easier | App stores backed by giant corporations have created choke points for the internet, which governments are now exploiting. | By FARHAD MANJOO | https://www.nytimes.com/2017/01/18/technology/clearing-out-the-app-stores-government-censorship-made-easier.html | 2017-01-18 | 05:00:26-5:00 |
| Caring for Smart Chip Cards | The newer type of credit and bank cards can be damaged in some of the same ways as their magnetic-stripe ancestors. | By J. D. BIERSDORFER | https://www.nytimes.com/2017/02/15/technology/personaltech/caring-for-smart-chip-cards.html | 2017-02-15 | 12:33:35-5:00 |
| Daily Report: The Fate of Science Fairs | Intel’s plans to stop sponsoring the International Science and Engineering Fair raise questions on what role companies should play in promoting science fairs and education. | By PUI-WING TAM | https://www.nytimes.com/2017/02/15/technology/daily-report-the-fate-of-science-fairs.html | 2017-02-15 | 12:27:25-5:00 |
| Coming to Video Games Near You: Depressed Towns, Dead-End Characters | A new game, Night in the Woods, is one of several in recent years that have tapped into themes of the decline of working-class towns and economic despair. | By LAURA HUDSON | https://www.nytimes.com/2017/02/15/technology/personaltech/coming-to-video-games-near-you-depressed-towns-dead-end-characters.html | 2017-02-15 | 10:12:18-5:00 |
| Why I Still Love TiVo and How a Sous Vide Gadget Rescued Me | No ads on TiVo is a timesaver, and its interface is better than a cable box, James Poniewozik says. | By JAMES PONIEWOZIK | https://www.nytimes.com/2017/02/15/technology/personaltech/why-i-still-love-tivo-and-how-a-sous-vide-gadget-rescued-me.html | 2017-02-15 | 05:00:13-5:00 |
| Intel Drops Its Sponsorship of Science Fairs, Prompting an Identity Crisis | The chip giant is ending its support of the fairs and sponsoring newer events like homemade engineering contests. Critics say the traditional fairs are as vital as ever. | By STEVE LOHR | https://www.nytimes.com/2017/02/14/technology/intel-drops-its-sponsorship-of-science-fairs-prompting-an-identity-crisis.html | 2017-02-14 | 22:30:16-5:00 |
| Apple Tiptoes Into Producing Original Video but Plans to Pick Up Pace | The technology giant said it would introduce its first two shows this spring. Others, including scripted dramas, are in the pipeline. | By VINDU GOEL | https://www.nytimes.com/2017/02/14/business/apple-video-amazon-netflix.html | 2017-02-14 | 05:06:43-5:00 |
| Daily Report: Tech Spreads Further Into Hospitality and Banking | For one industry, technology has allowed it to better serve customers. For the other, it has exposed some of the digital world’s perils. | By PUI-WING TAM | https://www.nytimes.com/2017/02/14/technology/daily-report-tech-spreads-further-into-hospitality-and-banking.html | 2017-02-14 | 10:29:10-5:00 |
| Virtual Reality on the Cheap? Try These Apps on Your Phone | A variety of apps, some using Google’s Cardboard viewer, allow users to sample films and games with 3-D imagery. | By KIT EATON | https://www.nytimes.com/2017/01/11/technology/personaltech/virtual-reality-on-the-cheap-try-these-apps-on-your-phone.html | 2017-01-11 | 10:22:38-5:00 |
| Hacked Yahoo Data Is for Sale on Dark Web | A security researcher says hackers are offering records of more than 1 billion users, but as with the company’s stock, the price is dropping. | By VINDU GOEL and NICOLE PERLROTH | https://www.nytimes.com/2016/12/15/technology/hacked-yahoo-data-for-sale-dark-web.html | 2016-12-15 | 21:52:22-5:00 |
| A New Destination for Files Downloaded From Microsoft Edge | Microsoft’s Windows 10 browser puts files in the Downloads folder by default, but you can pick a new place to store those fresh-off-the-web items. | By J. D. BIERSDORFER | https://www.nytimes.com/2017/01/12/technology/personaltech/a-new-destination-for-files-downloaded-from-microsoft-edge.html | 2017-01-12 | 12:16:08-5:00 |
| How an Overstuffed Mac Gets Its Drive Back | The latest version of Apple’s operating system has a feature that allows the computer to automatically delete certain files when space gets tight. | By J. D. BIERSDORFER | https://www.nytimes.com/2017/01/11/technology/personaltech/how-an-overstuffed-mac-gets-its-drive-back.html | 2017-01-11 | 12:35:51-5:00 |
| Watch PBS Shows Online or Off | Just because it’s public television does not mean all the shows are free, but you can stream and view content in many ways. | By J. D. BIERSDORFER | https://www.nytimes.com/2017/01/10/technology/personaltech/watch-pbs-shows-online-or-off.html | 2017-01-10 | 12:44:50-5:00 |
| One Phone, Many Instagram Accounts | The social photography app for Android and iOS can support up to five accounts, and you can easily switch among them. | By J. D. BIERSDORFER | https://www.nytimes.com/2017/01/09/technology/personaltech/one-phone-many-instagram-accounts.html | 2017-01-09 | 12:19:16-5:00 |
| 2016 in Review: The Year’s Best Apps | A news curator based on what friends are reading, an easy-to-access universe of NPR audio, and an upgraded beer-tracking app are among our top picks. | By KIT EATON | https://www.nytimes.com/2016/12/14/technology/personaltech/best-apps.html | 2016-12-14 | 12:06:37-5:00 |
| Text Messaging Takes More Apps Into a Chattier Realm | Texts have become so ingrained that apps have borrowed the chat format for storytelling, news or gaming. | By KIT EATON | https://www.nytimes.com/2016/12/28/technology/personaltech/text-messaging-takes-more-apps-into-a-chattier-realm.html | 2016-12-28 | 11:36:41-5:00 |
| Ways to Tap Into the Force, and Beam Up Your Inner Trekkie | For fans of “Star Wars,” “Star Trek” and science fiction, in a galaxy right here today, there is a lot of content designed for the supercomputer smartphone in your pocket. | By KIT EATON | https://www.nytimes.com/2016/12/21/technology/personaltech/ways-to-tap-into-the-force-and-beam-up-your-inner-trekkie.html | 2016-12-21 | 12:25:09-5:00 |