Sys.putenv(no_proxy = "") mkhtml <- function (source = "doit.R", dest = "index.html", width=480, height=480, nlig = NULL) { sapply(1:999, sprintf, fmt="fig%03d.png") -> fnames readLines(source) -> code grep("###begin", substring(code, 1, 8)) -> begins grep("###end", substring(code, 1, 6)) -> ends if( length(begins) != length(ends) ) stop("unbalanced begins and ends") output <- file(dest, open="w") # # write header # writeLines("Rweb
", output) # # main loop # for( i in 1:length(begins) ) { tmpfname <- tempfile() tmpfile <- file(tmpfname, open="w") writeLines( code[(begins[i]+1):(ends[i]-1)], tmpfile) close(tmpfile) available <- fnames[!file.exists(fnames)] png(available[1], width = width, height = height) source(tmpfname) dev.off() line <- sprintf("", available[1]) writeLines(line, output) writeLines("
", output) if( is.null(nlig) ) { nlig <- ends[i] - begins[i] - 1 } line <- sprintf("

", output) writeLines("

",output) } # # write footer # writeLines("
", output) close(output) }