How to create your own RSS reader with R

RSS feeds have been around since the late ’90s, and they remain a handy way to keep up with multiple news sources. Choose your feeds wisely, and your RSS reader will let you easily scan headlines from multiple sources and stay up to date on fast-moving topics. And while there are several capable commercial and open-source RSS readers available, it’s a lot more satisfying to code your own.

It’s surprisingly easy to create your own RSS feed reader in R. Just follow these eight steps.

Create a Quarto document or R script file

You can use a plain R script, but Quarto adds some useful, out-of-the-box styling. Quarto also gives you easier access to using JavaScript for the final display if you so choose. But the tutorial code works fine in an R file, too.

Unlike an R script, though, my Quarto document needs a YAML header to start. I’ll add a few settings in the YAML to generate a single HTML file (embed-resources: true), and not display my code (echo: false) or any code messages or warnings:

---
title: "Sharon's RSS Feed"
format:
html
embed-resources: true
editor: source
execute:
echo: false
warning: false
message: false
---

Load needed packages

Next, I’ll add some R code inside an R code block (```r and ``` enclose a block of executable code in Quarto; you don’t need those if you’re using a plain R script) and load the packages I’ll need. As you might guess from its name, tidyRSS is a library for reading RSS feeds into R.

``r
library(tidyRSS)
library(dplyr)
library(DT)
library(purrr)
library(stringr)
library(lubridate)
```

Add RSS feeds

Selecting relevant feeds is a key part of a useful RSS reader experience. I find mine based on sources I like and then checking websites or searching to see if RSS feeds exist. (As an optional exercise, you can use the rvest package to read sitemaps and wrangle them into RSS format, but that’s beyond the scope of this tutorial. Maybe in a future article!)

You may want to store your feeds in a separate CSV or Excel file and have your app import them. This way, you don’t have to touch the app code each time you update your feed list. For the sake of demo simplicity here, though, I’ll create a data frame in my script file with the feeds I want and my titles for each.

Since I write for both InfoWorld and Computerworld I’ll add both of those feeds. In addition, I’ll pull in a few R-specific RSS feeds, including R-Bloggers, R Weekly, and Mastodon’s #rstats and #QuartoPub RSS feeds at fosstodon.org, the Mastodon instance I use. In the code below, I save the feed info to a data frame call myfeeds with both feed URLs and my desired title for each feed. I then arrange them by feed title:

```r
myfeeds <- data.frame(feed_title = c("All InfoWorld",
"All Computerworld",
"Mastodon rstats",
"Mastodon QuartoPub",
"R Bloggers",
"R Weekly"),
feed_url = c("https://www.infoworld.com/index.rss",
"https://www.computerworld.com/index.rss",
"http://fosstodon.org/tags/rstats.rss",
"http://fosstodon.org/tags/QuartoPub.rss",
"https://feeds.feedburner.com/Rbloggers",
"https://rweekly.org/atom.xml")
) |>
arrange(feed_title)
```

Note: From here on, I won’t be including the ```r ``` Quarto code “fences” around the R code. All the rest of the R code still needs to be “fenced” in a Quarto doc, though.

Leave a Reply