# This script takes an RMarkdown file of a lecture chapter (or optionally multiple chapters) and renders them # into html files, two versions: one with a table of contents, and one without. The students like the ones # with the tables of contents, but for presenting onscreen with the ipad the version without the TOC is better. # I then use a further script (with git) to upload the html files to the webserver. # # Usage: First, "source" this file to define the functions. Then, # to render chapters 2, 3 and 4, type multirender(c('02','03','04')) # Can also render files that aren't named chapter_0n by using the multirender_nonchapter command. # # Note that you will have to set the "loc" variable manually to fit your file locations. library(rmarkdown) loc='/Users/kendra/Dropbox/WorkDocuments/Teaching/Courses/Stat 224/website/lectures' rmdpath<-function(number){ return(file.path(loc,paste0(number,'chapter.Rmd'))) } htmlpath<-function(number){ return(file.path(loc,paste0(number,'chapter.html'))) } htmltocpath<-function(number){ return(file.path(loc,paste0(number,'chapter_toc.html'))) } multirender <- function(numbers) { for(number in numbers){ render(rmdpath(number), output_format='html_document',output_file=htmlpath(number), output_options=list(toc=FALSE),params=list(dotabs=TRUE),envir=globalenv()) render(rmdpath(number), output_format='html_document',output_file=htmltocpath(number), output_options=list(toc=TRUE,css="styles_small.css"),params=list(dotabs=FALSE),envir=globalenv()) } } multirender_nonchapter <- function(name) { render(file.path(loc,paste0(name,'.Rmd')), output_format='html_document',output_file=file.path(loc,paste0(name,'.html')), output_options=list(toc=FALSE),params=list(dotabs=TRUE),envir = new.env()) render(file.path(loc,paste0(name,'.Rmd')), output_format='html_document',output_file=file.path(loc,paste0(name,'_toc.html')), output_options=list(toc=TRUE,css="styles_small.css"),params=list(dotabs=FALSE),envir = new.env()) } #multirender(c('02','03','04'))