knitr
Documents | Collaborative Editors | Workflows | Requirements knitr
package. This involves creating documents with mixtures of regular text to be typeset in a pdf
report and R code enclosed by a line containing <<>>= and a line containing @. When knitr
is run it produces a regular LaTeX document with all the results of the R computations and graphics inserted at the appropriate spots. knitr
also works with the easy-to-learn markdown
markup language which is especially suitable for student homework assignments and simple reports. But markdown
lacks the ability to handle complex tables, vector graphics that survive magnification, marginal notes, user extensions via macros and complex custom styles, and a full range of bibliographic citation styles. Also, markdown
will not produce manuscripts that meet journal style rules.
knitr
with LaTeX or markdown
makes statistical reports fully reproducible, but when writing a manuscript several problems arise, including In order to create reproducible manuscripts, it would be ideal if a single master file can be edited by both subject matter experts and statisticians, with statisticians being responsible for all the code in the document in addition to descriptions of statistical methods and interpretation of analyses. By creating a reproducible manuscript, all calculations can be re-done, tables and graphs recreated, and the new final manuscript produced by issuing a single command.
LaTeX has been the premier system for typesetting documents since the 1980s. It has its own markup language and is very easy to customize. The end result ispdf
or html
. LaTeX is used by many journal and book publishers. It is heavily used in the physical and mathematical sciences. An excellent introduction to LaTeX may be found https://tobi.oetiker.ch/lshort/lshort.pdf here and the LaTeX Cheetsheet may be found http://wch.github.io/latexsheet here. When you are working with a statistician, the statistician will have already created the document and the bibliographic database to cite, so collaborators need only concern themselves with editing paragraphs, sentences, section and subsection titles, and figure and table captions, and citing from the database. Here are some notes that show what non LaTeX users need to know to do such editing. The chunks of R code are edited by the statistician(s) on the team and should not be modified by collaborators except for figure captions. The goal here is to produce entire manuscripts that are reproducible, with final editing (including possible conversion to Word) deferred until submission time. During final editing, the journal's style is incorporated and any statistical results that are for supporting documentation and not for inclusion in the body of the paper are made to not be printed or are printed in an appendix at the end.
Manuscript writing involves a great deal of back-and-forth thinking and writing by collaborators. The philosophy here is that comments, questions, answers, to-do lists, and marginal notes are contained in the body of the paper. At the very end a command at the top of the document is changed so that these elements are not rendered in the final document. This process uses a custom LaTeX style we call spaper
for "paper with statistical results". The style may be downloaded from the attachments at the bottom of this paper.
Here are the main considerations that non-statistician collaborators will need to know when editing/adding sentences, paragraphs, sections, subsections, and figure captions or when citing papers or books. Most of the sentences you write will be just ordinary text as you always write. There are a few exceptions: The treatment reduced elasticity by 23\% but cost \$9,580 per patient.
See Figure~\ref{fig:anova}.
\emph{some text}
, and use \textbf{for boldface}
$_{thing to subscript}$
. What is between $ and $ (no escape \) is typeset in math mode.
$_{thing to superscript}$
.
\
%
. You can also put a %
in any line of regular text, without escaping it with \
. The text to the right of %
will be ignored.
enumerate
with itemize
.
Here are some special features of the spaper
style for inclusion of comments / discussions / questions / to do lists / short marginal flags in the document. \snote{your initials}
or \snote{CHECK}
.
\com*
command that the statistician defined for each author, e.g. \comfh{Some text}
. To use the general \com
command for an undefined author use \com{author initials or name}{comment of any length, line breaks ignored}
.
pdf
document, put the following line anywhere in the document after \usepackage{spaper}
. This way you do not need to remove the \com*
or \snote
commands in case you ever want to see their output again.
knitr
\ref{fig:chunkname}
where the referenced R chunk started with <The evidence for a treatment effect was strong (P=\Sexpr{pvalue}).
.Rnw
or .rnw
), the resulting final pdf
file, and the spaper
style file that is referenced by the document.
spaper.sty
requires Sweavel.sty
which is available here I | Attachment | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|
![]() |
spaper.Rnw | manage | 2 K | 07 Jun 2015 - 09:00 | FrankHarrell | Example LaTeX/knitr working manuscript |
![]() |
spaper.pdf | manage | 232 K | 07 Jun 2015 - 09:00 | FrankHarrell | Example working manuscript using LaTeX, R, knitr, spaper style |
![]() |
spaper.sty | manage | 2 K | 07 Jun 2015 - 09:02 | FrankHarrell | LaTeX style definition file for manuscripts with statistical analysis with R/knitr |