Abstract

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.

Environment Prep

if (!require('jsonlite')) install.packages('jsonlite')
if (!require('dplyr')) install.packages('dplyr')
if (!require('stringr')) install.packages('stringr')

Importing

Let’s use the Top Stories V1 API and look for stories in the Technology section.

Key Config

We have stored our API developer Key in a file called ‘configAPI.R’ and sourced below. The file is added to .gitignore. To use the rest of the code below, uncomment and add your developer key below.

# get our API key
source("configAPI.R")

# others should uncomment and paste in their key below
# key <- "my_developer_key""

# add text required for call
addkey <- paste0("&api-key=", key)

GET

# 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))

Setup DF

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)

Conclusion

knitr::kable(sub)
title abstract byline url pub_date pub_time
AT&T-Time Warner Deal Is a Strike in the Dark AT&T’s $85 billion deal for Time Warner is ploy to do something — anything — in the face of a rapidly changing media landscape. By FARHAD MANJOO http://www.nytimes.com/2016/10/25/technology/att-time-warner-deal-is-a-strike-in-the-dark.html 2016-10-24 19:59:25-5:00
How to Design Your Own Postage Stamps You can add a personal touch to your snail mail by creating custom stamps from your own photos. By J. D. BIERSDORFER http://www.nytimes.com/2016/10/25/technology/personaltech/how-to-design-your-own-postage-stamps.html 2016-10-24 13:12:35-5:00
Daily Report: Hackers Have New Tools to Bring Down Websites The so-called internet of things has the potential to connect billions of objects to the internet. That’s good news for troublemakers. By JIM KERSTETTER http://www.nytimes.com/2016/10/25/technology/daily-report-hackers-have-new-tools-to-bring-down-websites.html 2016-10-24 13:05:46-5:00
Nintendo Switch Console Is Met With Skepticism From Investors The game giant’s shares plummeted after it unveiled the all-in-one hardware, which can be played at home or on the go. By JONATHAN SOBLE http://www.nytimes.com/2016/10/22/business/international/nintendo-stock-switch-console.html 2016-10-21 04:41:07-5:00
As Artificial Intelligence Evolves, So Does Its Criminal Potential The next generation of online attack tools used by criminals will add machine learning capabilities pioneered by A.I. researchers. By JOHN MARKOFF http://www.nytimes.com/2016/10/24/technology/artificial-intelligence-evolves-with-its-criminal-potential.html 2016-10-23 18:18:22-5:00
David Bunnell, Whose Magazines Were Tech World Must-Reads, Dies at 69 Mr. Bunnell rode the early wave of personal computers, establishing PC Magazine, Macworld and other magazines and contributing to the industry’s explosive growth. By JOHN MARKOFF http://www.nytimes.com/2016/10/22/technology/david-bunnell-dead.html 2016-10-21 19:23:57-5:00
Farhad’s and Mike’s Week in Tech: The Political Evolution of Silicon Valley Tech is seeping into everything — but feels blindsided when its politics are called into question. Also, the Apple car and a short-term Twitter hire. By FARHAD MANJOO and MIKE ISAAC http://www.nytimes.com/2016/10/22/technology/farhads-and-mikes-week-in-tech-the-political-evolution-of-silicon-valley.html 2016-10-22 09:30:01-5:00
Hackers Used New Weapons to Disrupt Major Websites Across U.S. Users of Twitter, Netflix and other sites reported failures after a company managing crucial parts of the internet infrastructure said it was under attack. By NICOLE PERLROTH http://www.nytimes.com/2016/10/22/business/internet-problems-attack.html 2016-10-21 09:30:29-5:00
Keeping the Political Wool From Being Pulled Over Your Eyes These apps help you check facts, understand statistics and spot false arguments in this contentious election season. By KIT EATON http://www.nytimes.com/2016/10/20/technology/personaltech/keeping-the-political-wool-from-being-pulled-over-your-eyes.html 2016-10-19 11:14:59-5:00
Do You Have a Samsung Galaxy Note 7? Here’s What to Do Power down the device immediately. Then contact the wireless carrier or store where it was bought for details about a refund or exchange. By J. D. BIERSDORFER http://www.nytimes.com/2016/10/12/technology/personaltech/do-you-have-a-samsung-galaxy-note-7-heres-what-to-do.html 2016-10-12 00:00:00-5:00
How to Bid Adieu to Yahoo When you decide it’s time to close your account and move on to another mail service, make sure you get all the files you need before you go. By J. D. BIERSDORFER http://www.nytimes.com/2016/10/13/technology/personaltech/how-to-bid-adieu-to-yahoo.html 2016-10-12 12:40:40-5:00
After You Strengthen Your Passwords, Here’s How to Store Them Strong passwords are vital to digital security because they’re tougher to hack — but they’re also harder to remember. These secure apps can help. By KIT EATON http://www.nytimes.com/2016/10/06/technology/personaltech/after-you-strengthen-your-passwords-heres-how-to-store-them.html 2016-10-06 00:00:00-5:00
Donate Your Computer’s Spare Time to Science With the right software, you can give your computer’s spare processing power to a research project (and maybe make the world a better place). By J. D. BIERSDORFER http://www.nytimes.com/2016/10/20/technology/personaltech/donate-your-computers-spare-time-to-science.html 2016-10-19 12:26:56-5:00
When You Outgrow Your iCloud Storage Every iCloud user gets five free gigabytes of server space from Apple, but when space gets tight, you either have to prune or pay. By J. D. BIERSDORFER http://www.nytimes.com/2016/10/19/technology/personaltech/when-you-outgrow-your-icloud-storage.html 2016-10-18 12:04:31-5:00