This repository has been archived by the owner on May 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added R script to create html content for the full R intermediate boo…
…tcamp.
- Loading branch information
1 parent
5787ec4
commit 4bacbe7
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/Rscript | ||
|
||
# Knits all the files for the SWC intermediate R bootcamp | ||
|
||
# Should be executed from within the directory: bc/intermediate/r | ||
|
||
library(markdown) | ||
library(knitr) | ||
|
||
cwd <- normalizePath(getwd()) | ||
dirs <- strsplit(cwd, "/")[[1]] | ||
if (dirs[length(dirs)] != "r") { | ||
stop("This script needs to be run from within bc/intermediate/r.") | ||
} | ||
|
||
# Knit Rmd files to html, remove intermediate md files | ||
files <- list.files(pattern = "Rmd$", recursive = TRUE, full.name = TRUE) | ||
files <- normalizePath(files) | ||
for (fname in files) { | ||
setwd(dirname(fname)) | ||
knit2html(input = basename(fname), envir = new.env()) | ||
unlink(sub(".Rmd$", ".md", basename(fname))) | ||
} | ||
|
||
# Convert md files to html | ||
setwd(cwd) | ||
files <- list.files(pattern = "\\.md$", recursive = TRUE, full.name = TRUE) | ||
files <- normalizePath(files) | ||
for (fname in files) { | ||
if (basename(fname) == "README.md") { | ||
next | ||
} | ||
renderMarkdown(file = fname, output = sub("md$", "html", fname)) | ||
} |