Skip to content

MDshuey/newsAPI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

News API

  • R client for newsAPIorg
  • v1 edition by mkearney, updated to v2 by MD

API key

  • Go to newsapi.org and register to get an API key.
  • Save the key as an environment variable
## my obscured key
NEWSAPI_KEY <- "4345e85e8ae1427480xxxxxxxxxxxxxx"

## save to .Renviron file
cat(
  paste0("NEWSAPI_KEY=", NEWSAPI_KEY),
  append = TRUE,
  fill = TRUE,
  file = file.path("~", ".Renviron")
)

Install

  • Install from Github
## install script
if (!"devtools" %in% installed.packages()) {
  install.packages("devtools")
}
devtools::install_github("MDshuey/newsAPI")

## load package
library(newsAPI)

Demo

  • Get all available news sources
## get all english language news sources (made available by newsapi.org)
src <- get_sources(language = "en")

## preview data
print(src, width = 500)
  • Pass news source names (IDs) to get_articles function
## apply get_articles function to each news source
df <- lapply(src.en$id[-c(42,50,53)], get_articles)
#42, 50, 53 are dud sources, and will return an error. 
## collapse into single data frame
df <- do.call("rbind", df)

## preview data
print(df, width = 500)

About

API wrapper/R client for accessing https://newsapi.org

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%