How to create your own RSS reader with R
source link: https://www.infoworld.com/article/3684068/how-to-create-your-own-rss-reader-with-r.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to create your own RSS reader with R
Sure, you could use one of the commercial or open-source RSS readers. But isn’t it more fun to code your own?
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.
Recommend
-
42
Tiny Tiny RSS Php 5.6, Postgresql or MySQL https://tt-rss.org/ Docker 安装,虽然 ttrss 官方给了自己的
-
11
Weader - A simple atom/rss feed reader for Android Oct 24, 2013 • Christer Weinigel Ever since Google cancelled Google Reader I’ve been looking for a new feed reader. I haven’t found one I like so far. I’ve tried Feedl...
-
16
Build your own feed reader It seems that Google Reader is the next thing which will be scooped up by the "everything must be social" maw that is Plus. It comes as no surprise to me, since both Reader and Buzz have been set to die...
-
14
What RSS reader/aggregator do you use? What RSS reader are you guys using? I’ve been using Feedly for some years now but I’m not the biggest fan of their UI ...
-
7
Zenreader: A 4.7 inches E-Ink RSS Reader Powered by ESP32 I have been long wanting a PDA of sorts with an E-Ink screen that allows me to read stuff on the Internet without eye strains. But the Kindle really suc...
-
8
An rss reader that doesn't try to do too much demo.mp4 Motivation I wanted a very minimal RSS reader that wasn't feature packed, but could be extended. Something super simple. ...
-
7
RSS React Native RSS Reader Aug 15, 2021...
-
5
Using a Different System?
-
10
Using a Different System?
-
16
Using a Different System?
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK