# Rscript source-guide.R sources.csv source-guide.txt
args <- commandArgs(trailingOnly = TRUE)
if (length(args) != 2L) stop("Pass the source CSV and an output text path.")
sources <- read.csv(args[1], colClasses = "character", fileEncoding = "UTF-8")
stopifnot(all(c("headline","publication_date","source","url") %in% names(sources)),
          nrow(sources) > 0, all(grepl("^https?://", sources$url)))
output <- c(sources$headline[1], paste("Published", sources$publication_date[1]), "",
            paste0(seq_len(nrow(sources)), ". ", sources$source, " — ", sources$url))
writeLines(enc2utf8(output), args[2], useBytes = TRUE)
