rip <- function(infile = NULL, outfile = NULL) { if (is.null(infile)) { infile <- load.dir() } if (!grepl("save.html$", infile)) stop("infile is not a save.html file") src <- readLines(infile) ############################## Remove style ############################### # We assume that ONLY knitr has written .knitr.inline within a ", src) if (any(style.begin == (style.inline-1))) { # We use [1] to guard against multiple matching style.begins start <- style.begin[which(style.begin == (style.inline-1))[1]] end <- style.end[which(style.end > start)[1]] src <- src[-c(start:end)] } ################ Remove "
on a line chunks.end <- grep("^.*$", src) # Extra protection chunkLine <- grep("^.*$", src) # Find which chunks.end lines are the right ones. # ie, chunks.end lines that are after chunkLine lines. chunks.end <- chunkLine[(chunkLine+1) %in% chunks.end]+1 lines <- mapply(seq, chunks.begin, chunks.end) src <- src[-unlist(lines)] ########################### Remove inline codes ########################### inline <- grep('', src)
src[inline] <- gsub('',
"", src[inline])
########################### Replace all "keep"s ###########################
src <- gsub("(.+[.])(keep)(code.*$)", "\\1r\\3", src)
src <- gsub("",
src)
editJs.end <- editJs.start + length(readLines("edit.js")) - 1
src <- src[-c(editJs.start:editJs.end)]
########################### Remove the buttons ############################
# Similarly, search for the starting line of "button.html", then
# remove from that line up to the end line
button.start <- grep("