initWriteup: Create skeleton for a report or guide.

View source: R/initWriteup.R

initWriteupR Documentation

Create skeleton for a report or guide.


The installed package includes a set of folders with document templates. initWriteup is simply an automated way to copy the template folder and skeleton document file into a new directory.

The current formats are:

  1. rmd2html-guide

  2. rmd2pdf-report

  3. rnw2pdf-guide-sweave

  4. rnw2pdf-report-sweave

  5. rmd2pdf-guide

  6. rnw2pdf-guide-knit

  7. rnw2pdf-report-knit

  8. rnw2pdf-slides-sweave

The names represent the "from" format (rmd or rnw), the "to" format (html or pdf), the document type (guide or report), and the chunck processing program (Sweave or knitr).

Each selection offers a self-contained working document and enough information to compile that document. It also includes a shell script that can compile the document.


initWriteup(type, dir = type)



One of these character strings: c("rmd2html-guide", "rmd2pdf-report", "rnw2pdf-guide-knit", "rnw2pdf-guide-sweave", "rmd2pdf-guide", "rnw2pdf-report-knit", "rnw2pdf-report-sweave", "rnw2pdf-slides-sweave")


Directory into which files are inserted. Type "." for current working directory. Default is a new directory with name equal to the type parameter


The normalized path of the new directory


The examples demonstrate all of the mix-and-match combinations of input document formats, output formats, and document types. The issues involved are more fully explained in the vignettes provided with the package, but a nutshell summary would be as follows.

Report or Guide?

In our terminology, a guide is a document that includes "raw" code examples and possibly output. A guide is intended for training/teaching purposes, it might be offered on In contrast, a report generally will now include "raw" code and only very rarely will it have raw output. Calculations should create tables and plots that are inserted as (in LaTeX, floating) tables and figures.

Markdown ("*.Rmd") or Noweb ("*.Rnw")?

Documents can be prepared in markdown "Rmd" or R noweb Rnw. Either type of document can include code chunks. For creating HTML output, markdown is perhaps the most workable format. For creating PDF output, the noweb document format is better. When PDF output is desired, a markdown document must be converted to tex and then to PDF. Some LaTeX features are lost in that process, but they are not lost if we prepare the document in a noweb format (which *is* a LaTeX file). The details are discussed in the vignettes available with this package.


The allowed components in a report or guide depend on whether the eventual output is HTML or PDF. Many features intended for PDF outpu will not work if the backend is changed to HTML. The converse is also true. While this may change in the future, at the current time, only the most basic document which does not include most of the features that we truly need will be compatible with both PDF and HTML output. That's why we need to have so many mix-and match combinations of document types and output formats.

We may have slide templates as well, at some point in future.


Paul Johnson <>


tdir <- tempdir()
cat("Will Create All Doc Types in Temp Dir:\n ", tdir, "\n")

doctype <- c("rmd2html-guide", "rmd2pdf-report",
          "rnw2pdf-guide-knit", "rnw2pdf-guide-sweave",
          "rmd2pdf-guide", "rnw2pdf-report-knit",
          "rnw2pdf-report-sweave", "rnw2pdf-slides-sweave")
folders <- vapply(doctype, function(x){
               initWriteup(x, dir = file.path(tdir, "todaytest", x))},
list.files(file.path(tdir, "todaytest"), recursive = TRUE)
## Compile one example in the rnw2pdf-report-sweave folder
list.files(file.path(tdir, "todaytest/rnw2pdf-report-sweave"))

## requires pdflatex on system
rnw2pdf("skeleton.Rnw", wd = file.path(tdir, "todaytest/rnw2pdf-report-sweave"),
         engine = "Sweave")
## Check the pdf was created
list.files(file.path(tdir, "todaytest/rnw2pdf-report-sweave"))
if(interactive()) browseURL(file.path(tdir, "todaytest/rnw2pdf-report-sweave", "skeleton.pdf"))
unlink(file.path(tdir, "todaytest"), recursive = TRUE)

stationery documentation built on May 29, 2024, 4:56 a.m.