#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrartcl
\begin_preamble
% \VignetteIndexEntry{Instructions for rnw2pdf reports with knitted chunks}
% \VignetteEngine{knitr}
% \VignetteBuilder{stationery::rnw2pdf}
% \VignetteEncoding{UTF-8}


\usepackage[includehead,includefoot,
margin=1in,
rmargin=1in,
tmargin=0.75in,
bmargin=1.0in,
headheight=0pt,
headsep=0pt,
marginparwidth=0pt,
footskip=1.5\baselineskip,
]{geometry}

% \usepackage[yyyymmdd,hhmmss]{datetime}

\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{siunitx} %for semTable
%% PJ 20161110
%% I want to use listings in the document and I want nice/same as knitr.
%% Does knitr provide all of these settings for other listing uses outside
%% weaved part?


\input{theme/reportPreambleHeader.tex}
\input{theme/preambleFooter.tex}
%% Load Hyperref, don't let LyX do this
\input{theme/reportPreambleKnitr.tex}
\end_preamble
\use_default_options false
\begin_modules
logicalmkup
knitr
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding utf8
\fontencoding global
\font_roman "lmodern" "default"
\font_sans "lmss" "default"
\font_typewriter "lmtt" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 1
\bibtex_command default
\index_command default
\paperfontsize 11
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize letterpaper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 0
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date true
\justification true
\use_refstyle 0
\use_minted 0
\branch R
\selected 0
\filename_suffix 0
\color #faf0e6
\end_branch
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 1in
\topmargin 1in
\rightmargin 1in
\bottommargin 1in
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip medskip
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\noindent
\begin_inset ERT
status open

\begin_layout Plain Layout

%% Fill in values of the arguments here, 
\end_layout

\begin_layout Plain Layout

%% If blanks are needed, must insert value " ~ "
\end_layout

\begin_layout Plain Layout

%% If comma needed inside value, wrap in {}.
\end_layout

\begin_layout Plain Layout

%% Delete secondauthor and thirdauthor if not needed
\end_layout

\begin_layout Plain Layout


\backslash
reportsetup{%
\end_layout

\begin_layout Plain Layout

  author={
\end_layout

\begin_layout Plain Layout

    lastname=Johnson,
\end_layout

\begin_layout Plain Layout

    firstname=Paul~E., 
\end_layout

\begin_layout Plain Layout

    affiliation=Director{,}~CRMDA,
\end_layout

\begin_layout Plain Layout

    email=first@ku.edu},
\end_layout

\begin_layout Plain Layout

 author={
\end_layout

\begin_layout Plain Layout

    lastname=Sullivan, 
\end_layout

\begin_layout Plain Layout

    firstname=Meghan, 
\end_layout

\begin_layout Plain Layout

    affiliation=CRMDA, 
\end_layout

\begin_layout Plain Layout

    email=second@ku.edu},
\end_layout

\begin_layout Plain Layout

  title={Instructions for rnw2pdf reports with knitted chunks},
\end_layout

\begin_layout Plain Layout

  rightlogo={theme/logo.pdf},
\end_layout

\begin_layout Plain Layout

}
\end_layout

\begin_layout Plain Layout


\backslash
reporthdr
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

% 1.
 If you have an address file, use it here:
\end_layout

\begin_layout Plain Layout


\backslash
input{addressFooter.tex}
\end_layout

\begin_layout Plain Layout

% 2.
 If you don't have an address file, remove % signs and fill in your information
\end_layout

\begin_layout Plain Layout

% This stanza must end with 
\begin_inset Quotes eld
\end_inset


\backslash
guideftr
\begin_inset Quotes erd
\end_inset


\end_layout

\begin_layout Plain Layout

% (after removing percent signs):
\end_layout

\begin_layout Plain Layout

%
\backslash
urlstyle{tt}
\end_layout

\begin_layout Plain Layout

%
\backslash
footersetup{
\end_layout

\begin_layout Plain Layout

%  leftside={
\end_layout

\begin_layout Plain Layout

%    lone={Address line 1}, 
\end_layout

\begin_layout Plain Layout

%    ltwo={Address line 2}, 
\end_layout

\begin_layout Plain Layout

%    lthree={City State Zipcode}},
\end_layout

\begin_layout Plain Layout

%  rightside={
\end_layout

\begin_layout Plain Layout

%    rone={Web: 
\backslash
url{https://crmda.ku.edu}},
\end_layout

\begin_layout Plain Layout

%    rtwo={Email: 
\backslash
href{mailto:you@where.edu}{
\backslash
url{you@where.edu}}},
\end_layout

\begin_layout Plain Layout

%    rthree={Phone: 123-345-5678}}
\end_layout

\begin_layout Plain Layout

%}
\end_layout

\begin_layout Plain Layout

%
\backslash
guideftr
\end_layout

\begin_layout Plain Layout

% 3.
 If you don't want an address footer, just delete this subsection.
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<ignoremeRoptions, echo=FALSE>>=
\end_layout

\begin_layout Plain Layout

tdir <- "tmpout"
\end_layout

\begin_layout Plain Layout

if(!dir.exists(tdir)) dir.create(tdir, showWarnings=FALSE)
\end_layout

\begin_layout Plain Layout

library(stationery)
\end_layout

\begin_layout Plain Layout

opts.orig <- options()
\end_layout

\begin_layout Plain Layout

options(device = pdf)
\end_layout

\begin_layout Plain Layout

options(width=60, prompt=" ", continue="  ")
\end_layout

\begin_layout Plain Layout

options(useFancyQuotes = FALSE) 
\end_layout

\begin_layout Plain Layout

set.seed(12345)
\end_layout

\begin_layout Plain Layout

pdf.options(onefile=FALSE, family="Times", pointsize=10)
\end_layout

\begin_layout Plain Layout

if(!dir.exists("tmpout"))dir.create("tmpout", recursive = TRUE)
\end_layout

\begin_layout Plain Layout

## Code chunk settings
\end_layout

\begin_layout Plain Layout

library(knitr)
\end_layout

\begin_layout Plain Layout

opts_chunk$set(fig.path='tmpout/t-', split=FALSE, ae=FALSE, comment=NA,
\end_layout

\begin_layout Plain Layout

               fig.height=5, fig.width=6)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<ignoremeTexcopy, include=FALSE,echo=FALSE>>=
\end_layout

\begin_layout Plain Layout

## You can manually copy your desired 
\begin_inset Quotes eld
\end_inset

logo.pdf
\begin_inset Quotes erd
\end_inset

 into the theme folder.
 
\end_layout

\begin_layout Plain Layout

## Or This will retrieve a logo.pdf file if you want.
 Note overwrite parameter
\end_layout

\begin_layout Plain Layout

try(getFiles(
\begin_inset Quotes eld
\end_inset

logo.pdf
\begin_inset Quotes erd
\end_inset

, pkg = "stationery", overwrite = false))
\end_layout

\begin_layout Plain Layout

## If you do not have a file after that, 
\end_layout

\begin_layout Plain Layout

## the following will manufacture a blank image for a placeholder
\end_layout

\begin_layout Plain Layout

if(!file.exists(
\begin_inset Quotes eld
\end_inset

theme/logo.pdf
\begin_inset Quotes erd
\end_inset

)){
\end_layout

\begin_layout Plain Layout

  blankPDF(file = "theme/logo.pdf", height=1, width=3.5, messg = 
\begin_inset Quotes eld
\end_inset


\begin_inset Quotes erd
\end_inset

)
\end_layout

\begin_layout Plain Layout

}
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Abstract
\noindent
This shows how we use R 
\begin_inset CommandInset citation
LatexCommand citep
key "RCore"
literal "true"

\end_inset

 to make report documents using the CRMDA style.
 This is a LaTeX 
\begin_inset Quotes eld
\end_inset

noweb
\begin_inset Quotes erd
\end_inset

 report generated with the knitr engine.
\end_layout

\begin_layout Abstract
\begin_inset CommandInset toc
LatexCommand tableofcontents

\end_inset


\end_layout

\begin_layout Section
Introduction
\end_layout

\begin_layout Standard
Create a template (skeleton) document by opening R and running
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<eval=F>>=
\end_layout

\begin_layout Plain Layout

library(stationery)
\end_layout

\begin_layout Plain Layout

initWriteup("rnw2pdf-report-knit")
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
That will create a folder 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
rnw2pdf-report-knit
\end_layout

\end_inset

.
 If you do not want a directory to be created, then instead run
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<eval=F>>=
\end_layout

\begin_layout Plain Layout

library(stationery)
\end_layout

\begin_layout Plain Layout

initWriteup("rnw2pdf-report-knit", dir = 
\begin_inset Quotes eld
\end_inset

.
\begin_inset Quotes erd
\end_inset

)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
The 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
initWriteup
\end_layout

\end_inset

 function will create several files, including 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
skeleton.{lyx, Rnw}
\end_layout

\end_inset

, 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
instructions.{lyx, Rnw}
\end_layout

\end_inset

, as well as some auxiliary input files and a theme folder.
 
\end_layout

\begin_layout Section
Proceed as follows
\end_layout

\begin_layout Standard
If you allowed 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
initWriteup
\end_layout

\end_inset

 to create a directory, rename that directory in a way that will be helpful
 to your project.
 For example, 
\begin_inset Quotes eld
\end_inset

homework-1-2019
\begin_inset Quotes erd
\end_inset

 (anything that helps you remember what is in the write-up).
 
\end_layout

\begin_layout Standard
Decide whether you want to edit the LyX skeleton file (lyx) or the noweb
 skeleton (Rnw) file.
 
\end_layout

\begin_layout Enumerate
Copy the skeleton file to a new name.
 Choose a name that helps you, possibly 
\begin_inset Quotes eld
\end_inset

hw-1-2019.lyx
\begin_inset Quotes erd
\end_inset

 or such.
\end_layout

\begin_layout Enumerate
See the code chunk above named 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
ignoremeTexcopy
\end_layout

\end_inset

.
 That is used to retrieve image files for the header on page 1.
 If you don't have image logo files that you want to use, the last part
 of that chunk will manufacture empty 
\begin_inset Quotes eld
\end_inset

blank
\begin_inset Quotes erd
\end_inset

 pdf logo files.
 It is safe to delete the 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
ignoremeTexcopy
\end_layout

\end_inset

 chunk after you have the logo files you want in the theme folder.
 
\end_layout

\begin_layout Enumerate
Compile the document without making other changes.
 For instructions on compiling, see Section 
\begin_inset CommandInset ref
LatexCommand ref
reference "sec:Compile"
plural "false"
caps "false"
noprefix "false"

\end_inset

.
\end_layout

\begin_layout Enumerate
Make revisions incrementally.
 Start by inserting your own title and address information.
 Re-compile often to make sure no errors have been made.
 
\end_layout

\begin_layout Standard
Don't make changes that you don't understand in the 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
ignoremeRoptions
\end_layout

\end_inset

 code chunk above.
 For goodness sake, don't delete that one.
\end_layout

\begin_layout Section
Check our instructions
\end_layout

\begin_layout Standard
With every skeleton, we also provide an instructions file in the working
 directory.
\end_layout

\begin_layout Standard
There are also several vignettes distributed with the stationery package.
 Please review them.
\end_layout

\begin_layout Enumerate
\begin_inset Quotes eld
\end_inset

stationery
\begin_inset Quotes erd
\end_inset

: the package framework overview
\end_layout

\begin_layout Enumerate
\begin_inset Quotes eld
\end_inset

code_chunks
\begin_inset Quotes erd
\end_inset

: discusses display of code in LaTeX documents with both Sweave and knitr
 chunks
\end_layout

\begin_layout Enumerate
\begin_inset Quotes eld
\end_inset

Rmarkdown
\begin_inset Quotes erd
\end_inset

: about using Markdown with R, an alternative to LaTeX/Noweb.
\end_layout

\begin_layout Enumerate
\begin_inset Quotes eld
\end_inset

HTML Special Features
\begin_inset Quotes erd
\end_inset

: In Markdown intended for HTML output, authors can exploit some features.
 
\end_layout

\begin_layout Section
Compile the document
\begin_inset CommandInset label
LatexCommand label
name "sec:Compile"

\end_inset


\end_layout

\begin_layout Standard
The skeleton file is provided in 2 formats, LyX and Rnw.
 The stationery vignette has an overview of reasons why one might author
 with LyX, or with another program (with the 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
Rnw
\end_layout

\end_inset

 file).
 It also explains the compilation process.
 
\end_layout

\begin_layout Standard
Whether one writes the LyX file or the 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
Rnw
\end_layout

\end_inset

 file, it is necessary to understand that compiling is a two step process.
\end_layout

\begin_layout Enumerate
knitting: Run R to do the calculations in the R code chunks and write out
 a LaTeX file
\end_layout

\begin_layout Enumerate
compiling: Run a LaTeX program, such as 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
pdflatex
\end_layout

\end_inset

 or 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
xelatex
\end_layout

\end_inset

 or such.
 It is also necessary for a bibliography builder program to make a pass
 through the data.
 The aggregator program texi2pdf will this (if you have it).
\end_layout

\begin_layout Subsection
Working with the LyX file.
\end_layout

\begin_layout Enumerate
Use the LyX editor.
 Use the menus in the LyX editor.
 The file can be compiled to PDF in LyX, just like any other LyX file.
 A LyX module called 
\begin_inset Quotes eld
\end_inset

sweave
\begin_inset Quotes erd
\end_inset

 can be activated, so that compiling to PDF with the pdflatex program runs
 the chunks and builds a PDF.
 
\end_layout

\begin_layout Enumerate
Run LyX from the command line:
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ lyx -e pdf2 skeleton.lyx
\end_layout

\end_inset


\end_layout

\end_deeper
\begin_layout Enumerate
Open an R session, run
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

> library(stationery)
\end_layout

\begin_layout Plain Layout

> rnw2pdf("skeleton.lyx") # or .Rnw
\end_layout

\end_inset


\end_layout

\end_deeper
\begin_layout Enumerate
The shell script 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
rnw2pdf.sh
\end_layout

\end_inset

 is provided with the skeleton.
 Run:
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ ./rnw2pdf.sh skeleton.lyx
\end_layout

\end_inset


\end_layout

\end_deeper
\begin_layout Enumerate
In case you want to track the steps of compiling one by one, open the file
 in LyX.
 Use the pull down menu 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
File
\end_layout

\end_inset

 
\begin_inset Formula $\rightarrow$
\end_inset

 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
Export
\end_layout

\end_inset

 
\begin_inset Formula $\rightarrow$
\end_inset

 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
Rnw (knitr)
\end_layout

\end_inset

.
 That will create a file named 
\begin_inset Quotes eld
\end_inset

skeleton.Rnw
\begin_inset Quotes erd
\end_inset

.
 
\end_layout

\begin_deeper
\begin_layout Standard
This is the equivalent of the command line statement
\end_layout

\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ lyx -e knitr skeleton.lyx
\end_layout

\end_inset


\end_layout

\begin_layout Standard
After that Rnw file is created, proceed as described in the next subsection.
 
\end_layout

\begin_layout Standard
This two-step process is valuable for debugging.
 It makes it easier to spot trouble by focusing on the separate transitions.
\end_layout

\end_deeper
\begin_layout Subsection
Working with the Rnw file
\end_layout

\begin_layout Standard
The Rnw file we provide is produced by LyX.
 It is the traditional way that the R team developed Sweave and how most
 vignettes are made for packages.
\end_layout

\begin_layout Standard
The work flow here will vary, depending on your experience and the editor
 you choose to use.
 Here are some possibilities:
\end_layout

\begin_layout Enumerate
You may have a 
\begin_inset Quotes eld
\end_inset

noweb
\begin_inset Quotes erd
\end_inset

 aware editor.
 Emacs, Rstudio, and others have menus that can initiate the work of knitting
 and rendering the document.
\end_layout

\begin_layout Enumerate
Open an R session and make sure the working directory is the same as the
 project writeup.
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

> library(stationery)
\end_layout

\begin_layout Plain Layout

> rnw2pdf("skeleton.Rnw")
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Additional arguments can be used.
 Read help for 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
rnw2pdf
\end_layout

\end_inset

.
 Our function, by default, will create and R file summary of the command
 chunks.
 This file is referred to as a 
\begin_inset Quotes eld
\end_inset

purled
\begin_inset Quotes erd
\end_inset

 or 
\begin_inset Quotes eld
\end_inset

tangled
\begin_inset Quotes erd
\end_inset

 file.
 
\end_layout

\end_deeper
\begin_layout Enumerate
The shell script 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
rnw2pdf.sh
\end_layout

\end_inset

 is provided with the skeleton.
 Run
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ ./rnw2pdf.sh --engine='"knitr"' skeleton.Rnw
\end_layout

\end_inset


\end_layout

\begin_layout Standard
The command line script answers to all of the arguments allowed by the R
 function 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
rnw2pdf
\end_layout

\end_inset

.
 The usage is nearly identical.
 Where the R function call would be 
\end_layout

\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

rnw2pdf("skeleton.lyx", engine = "knitr", purl = FALSE, clean = FALSE, verbose
 = TRUE, keep_tex = TRUE)
\end_layout

\end_inset


\end_layout

\begin_layout Standard
the shell command would be
\end_layout

\begin_layout Standard
\begin_inset listings
lstparams "style=Rinput"
inline false
status open

\begin_layout Plain Layout

$ ./rnw2pdf --engine='"knitr"' --purl=FALSE --clean=FALSE --keep_tex=TRUE
 --verbose=TRUE skeleton.lyx
\end_layout

\end_inset


\end_layout

\begin_layout Standard
The only difference in usage arises when a quoted string must be passed
 through, such as 
\begin_inset Quotes eld
\end_inset

knitr
\begin_inset Quotes erd
\end_inset

, which must be protected in the command line by single quotes.
\end_layout

\end_deeper
\begin_layout Enumerate
This is the old fashioned way (therefore most virtuous for senior R users).
 
\end_layout

\begin_deeper
\begin_layout Enumerate
Step 1:
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ R CMD knit skeleton.Rnw
\end_layout

\end_inset


\end_layout

\begin_layout Standard
That will create 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
skeleton.tex
\end_layout

\end_inset

.
 
\end_layout

\end_deeper
\begin_layout Enumerate
Step 2:
\end_layout

\begin_deeper
\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

$ texi2pdf skeleton.tex
\end_layout

\end_inset


\end_layout

\begin_layout Standard
The major difference between running this and the script we provide is that
 our script will handle LyX files and it will, by default, create a purled
 copy of the R code.
 
\end_layout

\end_deeper
\end_deeper
\begin_layout Section
Editor Cautions
\end_layout

\begin_layout Subsection*
Rstudio
\end_layout

\begin_layout Standard
While editing an Rnw file in Rstudio, there will be a button labeled knit
 and a small triangle by that item.
 It is very (VERY!) important to choose the correct output format.
 If you choose incorrectly, Rstudio may damage your document by trying to
 revise it.
\end_layout

\begin_layout Subsection*
LyX
\end_layout

\begin_layout Standard
The document preamble has manual settings for margins (geometry) as well
 as hyperlinks (PDF hyperref).
 At the current time, these settings are not integrated with the LyX settings.
 As a result, using the LyX pull down menu to revise geometry and PDF hyperrefs
 may break the document entirely.
 To change those features, please edit the document preamble or config files.
 Repeat 
\series bold
CAUTION
\series default
: Don't change the page margins or settings for hyperlinks with pull down
 menus.
\end_layout

\begin_layout Section
What to edit
\end_layout

\begin_layout Subsection*
Title and author information
\end_layout

\begin_layout Standard
The first block in the document has the title and author information.
 
\end_layout

\begin_layout Subsection*
Footer information
\end_layout

\begin_layout Standard
The footer in this document uses data that is provided in a file named 
\begin_inset Quotes eld
\end_inset

addressFooter.tex
\begin_inset Quotes erd
\end_inset

.
 If you don't have an addressFooter.tex file, the address can be entered
 directly into this document.
\end_layout

\begin_layout Subsection*
About the theme folder
\end_layout

\begin_layout Standard
The theme folder should will have copies of the theme files, but the logo
 files are not copied until the document is compiled for the first times.
 It is done that way to preserve the author's customizations.
\end_layout

\begin_layout Standard
Authors are free to edit the theme files, to replace logo images.
\end_layout

\begin_layout Section
Math Check
\end_layout

\begin_layout Standard
A linear regression is an estimate of this theoretical model, which is displayed
 as a numbered equation
\begin_inset Formula 
\begin{equation}
y_{i}=\beta_{0}+\beta_{1}x1_{i}+\beta_{2}x2_{i}+\varepsilon_{i}\label{eq:linear}
\end{equation}

\end_inset


\end_layout

\begin_layout Standard
The equation can be referred to as equation (
\begin_inset CommandInset ref
LatexCommand ref
reference "eq:linear"
plural "false"
caps "false"
noprefix "false"

\end_inset

).
\end_layout

\begin_layout Section
Code Chunk Check
\end_layout

\begin_layout Subsection*
Reports don't include raw code chunks
\end_layout

\begin_layout Standard
What is the difference between a guide and a report? Simply put, a report
 document does not reveal source code and it should not distract the reader
 with raw output.
 A report is supposed to be presentable to a non R user.
 
\end_layout

\begin_layout Standard
As a result, it is important to think about whether to embed the R code
 in the document at all.
 One might keep the R code in another file, and use it to generate graphs
 and tables that can be included into this report document.
 
\end_layout

\begin_layout Standard
As we have mentioned in the 
\begin_inset Quotes eld
\end_inset

code_chunks
\begin_inset Quotes erd
\end_inset

 vignette, there are some differences in the way code chunks are used in
 Sweave and knitr.
 These differences are especially important in controlling whether, and
 where, the output of code chunks is presented in a document.
 Of all of the changes brought by the knitr code chunk engine, the proliferation
 of chunk options will be the most noticeable.
 The author of the knitr engine, Yihui Xie, maintains the canonical documentatio
n on code chunk options on his website, 
\begin_inset Flex URL
status open

\begin_layout Plain Layout

https://yihui.name/knitr/options
\end_layout

\end_inset

.
\end_layout

\begin_layout Standard
To prevent the code chunks from printing their input and raw output into
 the document, the code chunks will often employ flags like 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
include=FALSE
\end_layout

\end_inset

, 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
echo=FALSE
\end_layout

\end_inset

, and 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
results=
\begin_inset Quotes erd
\end_inset

hide
\begin_inset Quotes erd
\end_inset


\end_layout

\end_inset

.
 The code will need to write the tables and figures into files, and they
 can be inserted when it suits the author to do so.
 
\end_layout

\begin_layout Subsection*
Pleasant Output Tables
\end_layout

\begin_layout Standard
There are many R packages that generate LaTeX output which is presentable,
 close to the final desired result.
 In the development process, we will use these nearly-good-enough tables
 and then, when a final presentation demands find-grained adjustments, we
 do so manually on the table files.
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<m1, include=F, results=
\begin_inset Quotes erd
\end_inset

hide
\begin_inset Quotes erd
\end_inset

>>=
\end_layout

\begin_layout Plain Layout

dat <- data.frame(x = rnorm(100), y = rnorm(100))
\end_layout

\begin_layout Plain Layout

m1 <- lm(y ~ x, data = dat)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Some examples of nearly-good-enough tables are now presented.
 The regression result presented in Table 
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:A-Regression-Table"

\end_inset

 may not be perfect by APA standards, but it is certainly good enough for
 intermediate versions.
 This is produced by the 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
outreg()
\end_layout

\end_inset

 function in the rockchalk package.
 There are, of course, many other packages designed to generate the same
 sort of LaTeX markup.
\end_layout

\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
A Regression Table
\begin_inset CommandInset label
LatexCommand label
name "tab:A-Regression-Table"

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset ERT
status open

\begin_layout Plain Layout

<<outreg1, echo=F, results='asis'>>=
\end_layout

\begin_layout Plain Layout

library(rockchalk)
\end_layout

\begin_layout Plain Layout

vl <- c("x" = "Excellent Predictor")
\end_layout

\begin_layout Plain Layout

or <- outreg(list("First Model" = m1), varLabels = vl, tight = FALSE, centering
 = 
\begin_inset Quotes eld
\end_inset

siunitx
\begin_inset Quotes erd
\end_inset

)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
In the kutils package, we made a function 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
semTable()
\end_layout

\end_inset

 that presents structural equation models.
 The result in Table 
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:A-Confirmatory-Factor"

\end_inset

 is an example.
 
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<include=F>>=
\end_layout

\begin_layout Plain Layout

library(kutils)
\end_layout

\begin_layout Plain Layout

require(lavaan)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<cfa1, echo=F, include=F>>=
\end_layout

\begin_layout Plain Layout

HS.model <- 'visual  =~ x1 + x2 + x3
\end_layout

\begin_layout Plain Layout

textual =~ x4 + x5 + x6
\end_layout

\begin_layout Plain Layout

speed   =~ x7 + x8 + x9'
\end_layout

\begin_layout Plain Layout

output1 <- cfa(HS.model, data = HolzingerSwineford1939, std.lv = TRUE)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<cfa3, echo=F, include=F, results='asis'>>=
\end_layout

\begin_layout Plain Layout

cfa1 <- semTable(output1, fits = "rmsea", paramSets = c("loadings", "latentvaria
nces"), type = "latex")
\end_layout

\begin_layout Plain Layout

cat(cfa1, file="tmpout/t-cfa3.tex")
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
A Confirmatory Factor Analysis Table
\begin_inset CommandInset label
LatexCommand label
name "tab:A-Confirmatory-Factor"

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
input{tmpout/t-cfa3.tex}
\end_layout

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
In the perfect world, the tables that come from software would be perfectly
 presentable.
 This is the idea of the fully reproducible research document.
 At the current time, that is unrealistic.
 Authors need to leave a back door though which they can answer the very
 demanding requirements of journals and colleagues who insist on tables
 aligned 
\begin_inset Quotes eld
\end_inset

just so
\begin_inset Quotes erd
\end_inset

 with labels that have particular styles.
 The software will more closely approach that ideal, of course.
 But, for now, we make due.
 
\end_layout

\begin_layout Standard
In R, literate documents (using either knitr or Sweave) can be created with
 the document option 
\begin_inset Quotes eld
\end_inset

split
\begin_inset Quotes erd
\end_inset

 set as TRUE.
 If this is done, then an output file is generated for each and every the
 individual code chunk.
 In the CRMDA, our custom is to save these in a directory called 
\begin_inset Quotes eld
\end_inset

tmpout
\begin_inset Quotes erd
\end_inset

.
 The split option is not allowed in documents prepared as R vignettes, but
 it is still possible to get the work done.
 R has functions, mainly 
\begin_inset Flex Code
status open

\begin_layout Plain Layout
cat
\end_layout

\end_inset

, that can be used to save output tables.
\end_layout

\begin_layout Section
Session Information
\end_layout

\begin_layout Standard
Leave the code chunks below.
 Session Information is usually not written into a report, but an output
 file is created by the following pieces.
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<session, include=F>>=
\end_layout

\begin_layout Plain Layout

zz <- gsub("Rnw", "Rout", knitr::current_input())
\end_layout

\begin_layout Plain Layout

capture.output(sessionInfo(), file = zz, append = FALSE)
\end_layout

\begin_layout Plain Layout

if (!is.null(warnings())){
\end_layout

\begin_layout Plain Layout

    capture.output(warnings(), file = zz, append = TRUE)
\end_layout

\begin_layout Plain Layout

}
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

<<RoptionsRestore, echo=F, include=F>>=
\end_layout

\begin_layout Plain Layout

## Don't delete this.
 It puts the interactive session options
\end_layout

\begin_layout Plain Layout

## back the way they were.
 If this is compiled within a session
\end_layout

\begin_layout Plain Layout

## it is vital to do this.
\end_layout

\begin_layout Plain Layout

options(opts.orig)
\end_layout

\begin_layout Plain Layout

@
\end_layout

\end_inset


\end_layout

\end_body
\end_document
