From the command line: quarto render reportTemplate.qmd
Inside RStudio: press Render from a recent RStudio
Commenting/annotation/highlighting
If you have a free account with hypothes.is, will be placing the report on a permanent location on a web server, and want to enable highlighting, comments, and annotations by readers of the report, set hypothesis: true See https://quarto.org/docs/output-formats/html-basics.html#commenting
Note on markdown tables
To keep markdown tables from devoting more space to a column than needed, make the second line of the table look like -|-|-|
Use require(Hmisc); getRs('kable.r', put='source') to get the kabl function which makes it easy to combine multiple tables into one block
Thanks to Max Rohde for starting this template.
Code
require(Hmisc)# Make base graphics look better:spar <-function(bot=0, left=0, top=0, rt=0)par(mar=c(3.25+ bot, 5+ left, 0.5+ top, 0.5* rt),lwd=1.75, mgp=c(2.0, 0.475, 0), tcl=-0.4, xpd=FALSE, ps=14,cex.lab=1.15, cex.axis=0.8)# Set abbreviations for chunk option namesknitr::set_alias(w ='fig.width', h ='fig.height')options(prType='html') # for certain Hmisc and rms functions# Get dataset from Dept of Biostatistics dataset repositorygetHdata(pbc)pbc[1:20, 1:8]
# Take two tables and produce one html sectiongetRs('kable.r', put='source') # makes kables easy to usekabl(pbc[1:20, 1:3], pbc[21:40, 1:4], caption='Two parts of `pbc` data frame')
A marginal note goes here. It can be as long as you want and can include raw R output.
Code
spar(top=1) # allow for title (title produced by default by hist)with(pbc, hist(albumin, nclass=30))
Code
# To just use the caption in the margin, use spar() and hist(..., main='')
Quarto has a nice way of letting you lay out plots. In the following example layout: [[1,1], [1]] in the chunk header1 specifies that there are two rows of plots, with the first row containing two plots and the second only one, with the one made wider to fill the whole space.
The yaml header in this template will cause both html and pdf files (throught LaTeX) to be produced. To only produce one output format, run e.g. quarto render my.qmd --to html.
To make your script dual-purpose you can’t always reliably use marginal notes in LaTeX using this quarto syntax:
some text … some text …
So automatically sense which output format is being created and create a character string that will work for both html and LaTeX. For LaTeX, a boxed note in the body of the document will appear.
# Make a temporary mNote string for illustrationmNote <-'.callout-note appearance="minimal"'
some text … some text …
Computing Environment
R version 4.1.3 (2022-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Pop!_OS 21.10
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Hmisc_4.7-0 ggplot2_3.3.3 Formula_1.2-4 survival_3.2-13
[5] lattice_0.20-45
To cite R in publications use:
R Core Team (2022).
R: A Language and Environment for Statistical Computing.
R Foundation for Statistical Computing, Vienna, Austria.
https://www.R-project.org/.
---title: "Project One"author: - name: First Last url: https://example.com affiliation: Vanderbilt University Department of Biostatisticsdate: last-modifiedformat: html: self-contained: true anchor-sections: true code-tools: true code-fold: true fig-width: 6 fig-height: 4 code-block-bg: "#f1f3f5" code-block-border-left: "#31BAE9" mainfont: Source Sans Pro theme: journal toc: true toc-depth: 3 toc-location: left captions: true cap-location: margin table-captions: true tbl-cap-location: margin reference-location: margin pdf: pdf-engine: lualatex toc: false number-sections: true number-depth: 2 top-level-division: section reference-location: document listings: false header-includes: \usepackage{marginnote, here, relsize, needspace, setspace} \def\it{\emph}comments: hypothesis: falseexecute: warning: false message: false---:::{.callout-tip collapse="true"}## Usage Notes* System setup + Install `quarto` executable from <https://quarto.org>* To compile report: + From the command line: `quarto render reportTemplate.qmd` + Inside RStudio: press `Render` from a recent RStudio* Commenting/annotation/highlighting + If you have a free account with `hypothes.is`, will be placing the report on a permanent location on a web server, and want to enable highlighting, comments, and annotations by readers of the report, set hypothesis: true See <https://quarto.org/docs/output-formats/html-basics.html#commenting>* Note on markdown tables + To keep markdown tables from devoting more space to a column than needed, make the second line of the table look like -|-|-| + Use `require(Hmisc); getRs('kable.r', put='source')` to get the `kabl` function which makes it easy to combine multiple tables into one blockThanks to Max Rohde for starting this template.:::```{r setup}require(Hmisc)# Make base graphics look better:spar <-function(bot=0, left=0, top=0, rt=0)par(mar=c(3.25+ bot, 5+ left, 0.5+ top, 0.5* rt),lwd=1.75, mgp=c(2.0, 0.475, 0), tcl=-0.4, xpd=FALSE, ps=14,cex.lab=1.15, cex.axis=0.8)# Set abbreviations for chunk option namesknitr::set_alias(w ='fig.width', h ='fig.height')options(prType='html') # for certain Hmisc and rms functions# Get dataset from Dept of Biostatistics dataset repositorygetHdata(pbc)pbc[1:20, 1:8]# Take two tables and produce one html sectiongetRs('kable.r', put='source') # makes kables easy to usekabl(pbc[1:20, 1:3], pbc[21:40, 1:4], caption='Two parts of `pbc` data frame')```# Descriptive Statistics```{r desc}html(describe(pbc))```::: {.column-margin}A marginal note goes here. It can be as long as you want and can include raw R output.:::```{r simpleplot}#| fig.cap: Histogram of serum albumin#| h: 2.5#| w: 4spar(top=1) # allow for title (title produced by default by hist)with(pbc, hist(albumin, nclass=30))# To just use the caption in the margin, use spar() and hist(..., main='')````Quarto` has a nice way of letting you lay out plots. In the following example `layout: [[1,1], [1]]` in the chunk header^[See [this](https://quarto.org/docs/authoring/figures.html) for more information] specifies that there are two rows of plots, with the first row containing two plots and the second only one, with the one made wider to fill the whole space.```{r plots3}#| layout: [[1,1], [1]]with(pbc, {spar()plot(bili, albumin)plot(albumin, protime)hist(albumin, nclass=25, main='') } )```# Running `quarto`The `yaml` header in this template will cause both `html` and `pdf` files (throught `LaTeX`) to be produced. To only produce one output format, run e.g. `quarto render my.qmd --to html`.To make your script dual-purpose you can't always reliably use marginal notes in `LaTeX` using this `quarto` syntax:::: {.column-margin}some text ...some text ...:::So automatically sense which output format is being created and create a character string that will work for both `html` and `LaTeX`. For `LaTeX`, a boxed note in the body of the document will appear.```ishtml <- knitr::is_html_output()mNote <- if(ishtml) '.column-margin' else '.callout-note appearance="minimal"'```Then use```{r defm}# Make a temporary mNote string for illustrationmNote <-'.callout-note appearance="minimal"'```::: {`r mNote`}some text ...some text ...:::# Computing Environment`r markupSpecs$html$session()`