Skip to content
Related Articles
Open in App
Not now

Related Articles

Get news from newsapi using R language

Improve Article
Save Article
Like Article
  • Last Updated : 18 Mar, 2022
Improve Article
Save Article
Like Article

In this article, we will learn how to create a Rscript to read the latest news. We will be using news API to get news and extract it using httr package in R Programming Language.

Modules Needed:



Get news API:

To get your API key visit and create your account. 

Click on the Get API key to get your key.  Make sure you have saved your key.

We will be using httr GET() to make URL requests and store news data in a variable. Now we will need JSON data so we have to convert the news data into char format because GET() returns raw data so we will need to use rawToChar() and to convert char data in JSON format we will be using from JSON() built-in jsonlite package.



# importing packages
# declaring url
# making http request and storing it in 
# news variable
news = GET(url)
# converting raw data to character
data = rawToChar(news$content)
# converting character to json format
jsondata = fromJSON(data)
# printing news title

Make sure to replace <YOURAPIKEY> with your API key in url.


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!