Nothing
# Render three standalone HTML lessons and one collected PDF guide.
# Usage: Rscript tools/render-tutorials.R /path/to/IJSE output_dir
args <- commandArgs(trailingOnly = TRUE)
stopifnot(length(args) == 2L)
root <- normalizePath(args[1L], mustWork = TRUE)
dir.create(args[2L], recursive = TRUE, showWarnings = FALSE)
output <- normalizePath(args[2L], mustWork = TRUE)
stage <- file.path(output, "render-source")
dir.create(stage, recursive = TRUE, showWarnings = FALSE)
names <- c("ijse", "ijse-brms", "ijse-diagnostics")
titles <- c("Tutorial 1: Getting Started with IJSE",
"Tutorial 2: brms, Clusters and Joint Contrasts",
"Tutorial 3: Diagnostics, Influence and Troubleshooting")
css <- file.path(root, "vignettes", "ijse.css")
file.copy(css, stage, overwrite = TRUE)
for (name in names) {
original <- file.path(root, "vignettes", paste0(name, ".Rmd"))
input <- file.path(stage, paste0(name, ".Rmd"))
file.copy(original, input, overwrite = TRUE)
rmarkdown::render(input,
output_format = rmarkdown::html_document(self_contained = TRUE,
highlight = NULL, css = file.path(stage, "ijse.css")),
output_file = paste0(name, ".html"), output_dir = output,
envir = new.env(), quiet = TRUE)
}
header <- c(
"---", 'title: "IJSE Tutorials: From First Calculation to Diagnostic Review"',
'date: "October 21, 2026"', "fontsize: 12pt",
"mainfont: Times New Roman", "sansfont: Times New Roman",
"monofont: Courier New", "geometry: margin=1in", "colorlinks: false",
"header-includes:",
' - \\usepackage{fvextra,titlesec}',
' - \\DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\\footnotesize,breaklines=true,breakanywhere=true,samepage=true}',
' - \\titleformat{\\section}{\\normalfont\\fontsize{14}{16}\\bfseries}{\\thesection}{0.6em}{}',
' - \\titleformat{\\subsection}{\\normalfont\\fontsize{12}{14}\\bfseries}{\\thesubsection}{0.6em}{}',
' - \\makeatletter\\renewcommand{\\maketitle}{\\begin{center}{\\fontsize{16}{18}\\selectfont\\bfseries\\@title\\par}\\vspace{0.5em}\\begingroup\\let\\vspace\\@gobble\\normalsize\\@date\\par\\endgroup\\end{center}\\vspace{0.5em}}\\makeatother',
"---", "",
"This guide contains three independently executable tutorials for IJSE 0.3.3.",
"Start with matched draws and likelihoods, continue with actual brms fits,",
"and finish with diagnostics and reproducible error cases. The companion",
"HTML lessons, R scripts and synthetic example fits are available separately.",
"Neither Stan compilation nor new model fitting is required to run the",
"evaluated tutorial code. Tutorial 2 requires brms; the other lessons do not.",
"")
book <- header
for (i in seq_along(names)) {
lines <- readLines(file.path(root, "vignettes", paste0(names[i], ".Rmd")))
boundary <- which(lines == "---")
stopifnot(length(boundary) >= 2L, boundary[1L] == 1L)
child <- paste0("child-", i, ".Rmd")
writeLines(lines[-seq_len(boundary[2L])], file.path(stage, child))
book <- c(book, paste0("# ", titles[i]), "",
paste0("```{r book-", i, ", echo=FALSE, results='asis'}"),
paste0("cat(knitr::knit_child('", child,
"', envir = new.env(), quiet = TRUE), sep = '\\n')"),
"```", "")
}
input <- file.path(stage, "IJSE-tutorial-guide.Rmd")
writeLines(book, input)
rmarkdown::render(input,
output_format = rmarkdown::pdf_document(latex_engine = "xelatex",
keep_tex = TRUE, highlight = NULL,
pandoc_args = c("--lua-filter",
file.path(root, "tools", "tutorial-codeblocks.lua"))),
output_file = "IJSE-tutorial-guide.pdf", output_dir = output,
envir = new.env(), quiet = TRUE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.