# reverses my blog from chronological order to reverse chronological # order reverse <- function() { # blog will be a vector of strings, one per line of the file blog <- readLines("Blog.html",-1) # determine at which lines the entries begin dates <- which(grepl("strong",blog)) # add a fake date for the last line in the file lb <- length(blog) dates <- c(dates,lb) # open output file cn <- file("newblog.html","w") # go through the entries in reverse order nd <- length(dates) - 1 # number of entries for (i in nd:1) { start <- dates[i] fin <- dates[i+1] - 1 cat("

",file=cn) writeLines(blog[start:fin],cn) cat("

\n\n",file=cn) } close(cn) }