## ----setup, include=FALSE----------------------------------------------------- knitr::opts_chunk$set( message = FALSE, warning = FALSE, comment = "#>" ) source("cache-hook.R") ## ----libs, message=FALSE, warning=FALSE--------------------------------------- library(textpress) library(dplyr) library(DT) ## ----web-urls, cache_rds = c("feeds", "web_urls")----------------------------- # feeds <- c( # textpress::rss_politics |> # filter(source == "Pew Research Center") |> # pull(url), # "https://theconversation.com/us/politics/articles.atom" # ) # # web_urls <- textpress::fetch_rss(feeds) |> # filter(grepl( # "midterm|election|voter|Congress", # paste(title, description), # ignore.case = TRUE # )) ## ----web-text, cache_rds = "web_text_list"------------------------------------ # web_text_list <- web_urls |> # textpress::read_urls(cores = 4) ## ----------------------------------------------------------------------------- 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( '', h1_title, '' ) ) DT::datatable( metas_dt |> select(date, source, title_link, text), options = list(columnDefs = list( list(targets = 2, orderable = FALSE) )), escape = FALSE, rownames = FALSE )