textpress is organized around four actions – fetch,
read, process, search. This vignette covers the first two.
fetch_rss() retrieves recent entries from
publisher-supported RSS and Atom feeds; read_urls() scrapes
their content into a node-level data frame while retaining that
provenance. Together they turn selected news sources into an
analysis-ready corpus in a few lines.
Select six outlets from the bundled rss_politics
catalog, use fetch_rss() to retrieve their recent entries,
and keep the five most recent from each before read_urls()
scrapes and parses the articles. The selection below is ordinary R
filtering of a data frame, not a query sent to a search service.
outlets <- c("NPR", "PBS News", "Fox News", "Los Angeles Times", "Vox", "The Dispatch")
textpress::rss_politics |>
filter(source %in% outlets) |>
select(source, feed, category, url) |>
DT::datatable(rownames = FALSE)
web_urls <- textpress::rss_politics |>
filter(source %in% outlets) |>
pull(url) |>
textpress::fetch_rss() |>
distinct(url, .keep_all = TRUE) |>
group_by(source) |>
slice_max(published_at, n = 5, with_ties = FALSE) |>
ungroup()Scrape and parse the URLs returned above into a node-level data frame
with $text and $meta components.
web_text_list <- web_urls |>
textpress::read_urls(cores = 4)Build a text snippet from the first 15 words of each article, join to metadata, and display as an interactive table.
snippets <- web_text_list$text |>
group_by(doc_id) |>
summarise(text = {
words <- unlist(strsplit(paste(text, collapse = " "), "\\s+"))
paste(paste(words[seq_len(min(15, length(words)))], collapse = " "), "...")
}, .groups = "drop")
metas_dt <- web_text_list$meta |>
filter(!is.na(h1_title) & nzchar(trimws(h1_title))) |>
left_join(snippets, by = "doc_id") |>
arrange(desc(date)) |>
mutate(
title_link = paste0(
'<a href="', url, '" target="_blank">', h1_title, '</a>'
)
)
DT::datatable(
metas_dt |> select(date, source, title_link, text),
options = list(columnDefs = list(
list(targets = 2, orderable = FALSE)
)),
escape = FALSE,
rownames = FALSE
)fetch_rss() and read_urls() are
source-to-corpus entry points for a textpress pipeline.
fetch_rss() returns publisher-provided article URLs with
feed metadata; read_urls() scrapes and parses them into
$text (one row per node) and $meta (one row
per URL, including discovery provenance).