#Vignettes that depend on internet access have been precompiled:
old_wd <- getwd()

setwd("vignettes/")

library(knitr)
knit("./source/_a-getting-started.Rmd",
     "a-getting-started.Rmd")
knit("./source/_b-advanced-ggplot.Rmd",
     "b-advanced-ggplot.Rmd")
knit("./source/_c-advanced-base.Rmd",
     "c-advanced-base.Rmd")

library(devtools)
build_vignettes()

# x = vignette file name including file extension (e.g., "a-getting-started.Rmd")
read_only <- function(x) {
  # Create file
  tmp <- file(x)
  # write lines
  writeLines(c(c("---"),
               c("# Generated by vignettes/precompile.R: do not edit by hand."),
               paste0("# Please edit source in vignettes/source/_", x),
               readLines(x)[2:length(readLines(x))]), tmp)
  close(tmp)
}
# Add read only info
read_only("a-getting-started.Rmd")
read_only("b-advanced-ggplot.Rmd")
read_only("c-advanced-base.Rmd")
rm(read_only)

setwd(old_wd)
