knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The substackR
package allows users to interact with the Substack API to retrieve various types of data from Substack publications. This includes fetching the latest posts, top posts, searching for specific content, and retrieving individual posts by their slug.
You can install the package from GitHub using the following command:
# install.packages("remotes") remotes::install_github("posocap/substackR")
Before using the package, you need to set your Substack API key:
library(substackR) set_substack_key("YOUR_API_KEY")
To fetch the latest posts from a Substack publication, use the get_substack_latest
function:
latest_posts <- get_substack_latest("posocap.substack.com", limit = 5) print(latest_posts)
You can also retrieve the most popular posts:
top_posts <- get_substack_top("posocap.substack.com", limit = 5) print(top_posts)
To search for specific posts, use the get_substack_search
function:
search_results <- get_substack_search("posocap.substack.com", query = "economics", limit = 5) print(search_results)
To get a single post by its slug:
single_post <- get_substack_post("posocap.substack.com", slug = "your-post-slug") print(single_post)
The substackR
package provides a simple and effective way to access Substack data, making it easier for developers and researchers to work with content from Substack publications.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.