library(magrittr) library(knitr) code_tree <- read.csv(file.path("Output","codetree.csv"), stringsAsFactors = FALSE) root <- code_tree[1,1] PATH <- gsub("\\\\ROOT$", "", root,perl=TRUE) code_tree %<>% within({ parent %<>% gsub("\\\\","/",., fixed=TRUE) %>% gsub(PATH,"", . ,fixed=TRUE) child %<>% gsub("\\\\","/",., fixed=TRUE) %>% gsub(PATH,"", . ,fixed=TRUE) }) graphcode <- function( edges, node, rootnode=TRUE){ #edges is a data.frame with two columns: parent, child if(length(node)){ children <- subset(edges, parent==node)$child if(!rootnode){ output <- " child{ "} if(rootnode){ output <- "" } output <- c(output, "node{ ", node,"} ") #if(rootnode){ output <- c(output, "[grow=right] ")} for( child in children){ output <- c(output, Recall(edges, child, rootnode=FALSE)) } if(!rootnode){ output <- c( output, " }")} } else{ output <- "" } output } graph <- graphcode(code_tree, code_tree[1,1]) graph <- gsub("\\\\","/", graph) graph <- gsub(PATH,"", graph) graph <- gsub("_"," ", graph) graph <- paste(c('\\',graph, ";"), collapse = "") graph #sibling distance=20em,
\begin{tikzpicture}[edge from parent fork right, level distance=20em, grow'=right,
every node/.style = {shape=rectangle, rounded corners,draw, align=center, fill=white}]
r knitr::knit_child(text=graph)
\end{tikzpicture}
This is generated a stand alone vignette, but really it woudl be called from a call in main.R
like
render("Progs/code_tree_doc.Rmd", output_file ="Vignette Code Tree.pdf",output_dir = "Output/Reports", params=list(my_author="Simon Bond", my_title= "Vignette Code Tree") )
NB use the file /doc/Progs/code_tree_docs.Rmd
and not the similarly named one within /doc
. Building vignettes requires these two slightly different versions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.