and Collaborating on Them with Git and GitHub
November 2026
Skip intro — To the contents slide.
Associate Professor at Durham University, UK
Data Editor at Political Communication, from January 2027
Teaching workshops, also on
resulumit.com has more about my work
First, with Stata + Word, I was …
Then, with Stata + R + LaTeX, I was …
frustrated with Word
tired of switching between programmes and screens
paying for the Stata licence
converting PDF documents to Word manually
Now, with R Markdown, and then Quarto, I am … happy!
frustrated with Word
tired of switching between programmes and screens
paying for the Stata licence
converting PDF documents to Word manually
* I demonstrate this example live during the workshop.
.qmd rather than .docx.qmd file.Rmd files can be rendered with Quarto as they areformat instead of output, and in chunk options — see Part 6.qmd files should just work* See the announcement and this blog post.
.qmd, are ideal for this workflow
Part 1. Getting the Tools Ready
e.g., downloading the materials
Part 2. Introducing Quarto
e.g., creating a new document
Part 3. Setting Metadata
e.g., defining output formats
Part 4. Writing Text
e.g., adding emphasis to text
Part 5. Managing References
e.g., citing sources
Part 6. Adding Code, Figures, and Tables
e.g., plotting data
Part 7. Fine-Tuning
e.g., referring to tables
Part 8. Using Version Control
e.g., integrating Git and GitHub
Part 9. Collaborating with Others
e.g., working simultaneously with co-authors
Part 10. Going Further
e.g., using journal formats
Slides with this background colour indicate that your action is expected, for example:
* If you followed the pre-workshop preparation, you should already have completed these steps. I will cover the relevant slides only briefly and answer any questions.
**bold**
Code -> Download ZIP
qmd_workshop-materials, as yourname-quarto
resul-quartoNotice that the folder, after renaming, has the following structure
yourname-quarto/
|
|- data/
| |- journals.csv
|
|- image/
| |- google_scholar.png
|
|- manuscript/
| |- apa_7th.csl
| |- journals.qmd
| |- references.bib
| |- reproduce_this.pdf
|
|- preparation/
| |- preparation_guide.pdf
| |- the_test.qmd
|
|- solutions/
| |- apa_7th.csl
| |- journals_after_part3.qmd
| |- ...
| |- journals_after_part7.qmd
| |- references.bib
manuscript/reproduce_this.pdf
¶ 22 and Ex. 13manuscript/journals.qmd
reproduce_this.pdf, to save time* The dataset is created with the fabricatr package (Blair et al. 2022).
solutions/journals_after_part3.qmd to solutions/journals_after_part7.qmd
journals.qmd should look at the end of Parts 3 to 7journals_after_part7.qmd has all exercises on the mock paper completedNote that, to catch up, you can replace the contents of
manuscript/journals.qmd with those of the relevant file, andmanuscript/references.bib with those of solutions/references.bibdata/journals.csv
a dataset created with the fabricatr package (Blair et al. 2022), imagined to explore the Google Scholar rankings of fictitious journals
includes the following variables
manuscript/references.bib
manuscript/apa_7th.csl
image/google_scholar.png
preparation/preparation_guide.pdf, and preparation/the_test.qmd
R.version.string in R to check your current version
Help -> Check for RStudio Updates
Terminal tab in RStudioTerminal tab in RStudioNote that
git --version in the Terminal; if Git is missing, macOS offers to install it, as part of its command line developer toolsasdf029348)...\yourname-quarto from the RStudio menu:
File -> New Project -> Existing Directory -> Browse -> ...\yourname-quarto -> Open
* Recall that we downloaded this earlier from GitHub. Back to the relevant slide.
Install the required R packages
quarto (Allaire and Dervieux 2025), for using Quarto from R, e.g., to add extensions
dplyr (Wickham, François, et al. 2023), for data manipulation
ggplot2 (Wickham 2016), for figures
modelsummary (Arel-Bundock 2022), for summary and regression tables
usethis (Wickham et al. 2025), gitcreds (Csárdi 2024), for Git and GitHub
preparation/the_test.qmd in RStudioRender buttonthe_test.pdf, will appear in the same folder
File -> New File -> Quarto Document... -> Create
File -> Save
.qmd extension* For demonstration only — we will otherwise work with journals.qmd. In the dialogue box, uncheck Use visual markdown editor for now.
** Alternatively, click the Save icon, the floppy disk in the toolbar above the document.
Observe also that the document has three components
--- title: "Untitled" format: html --- ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` The `echo: false` option disables the printing of code (only output is displayed).--- title: "Untitled" format: html --- ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` The `echo: false` option disables the printing of code (only output is displayed).--- title: "Untitled" format: html --- ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` The `echo: false` option disables the printing of code (only output is displayed).--- title: "Untitled" format: html --- ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` The `echo: false` option disables the printing of code (only output is displayed).--- title: "Untitled" format: html --- ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` The `echo: false` option disables the printing of code (only output is displayed).
Observe also that the editor toolbar offers extended tools for .qmd documents
These include, most importantly,
the Render button, to render .qmd documents
the Render on Save option, to render automatically every time you save
the Source and Visual buttons, to switch between the two editing modes
Render button to render your .qmd document, and observe that
.qmd documentViewer tab, or in your browser
**Render** in the text has become Render1 + 1 has run, and its result, [1] 2, is shown below itRender, Quarto orchestrates the following:*.qmd ---knitr---> .md ---pandoc---> output
knitr (Xie 2025) executes the code, if there is any, and turns the resulting document into Markdown (.md)
pandoc (MacFarlane 2026) transforms the .md document into your preferred output format(s)
.md ---pandoc---> .tex ---LaTeX---> .pdf* pandoc comes with Quarto, while knitr is an R package, installed together with the quarto package.
RStudio offers two modes for editing .qmd documents
Source mode shows the plain text, as it is saved
Visual mode shows a formatted, word-processor-like view
Visual re-writes your whole documentSource mode onlyFor those who already use R Markdown, the key differences* are
| R Markdown | Quarto | |
|---|---|---|
| File extension | .Rmd |
.qmd |
| Output format in YAML | output: pdf_document |
format: pdf |
| Chunk options | {r, echo=FALSE} |
#| echo: false |
| Option names | fig.cap, out.width |
fig-cap, out-width |
| Inline code | `r 1+1` |
`{r} 1+1` |
| Cross-references | \autoref{}, bookdown |
@fig-, @tbl-, built in |
| Render | Knit button |
Render button |
| Languages | mostly R | R, Python, Julia, Observable |
* The old syntax continues to work in most cases, but the new one is recommended.
.qmd file is rendered in its own, new R session
.qmd file* Here we will focus on research papers only. See the Quarto Guide for the others.
10:00
Visual mode, and make a word italics, using the formatting toolbarSource mode, and observe how the italic word is written in MarkdownFiles tab, the .qmd and .html files, and the folder with the same name, ending in _filesmanuscript/journals.qmd, and render it.qmd documents start* with YAML
* It is conventionally placed at the very beginning of the document, although Quarto also recognises it elsewhere, if preceded by a blank line.
title and format are the basic variables of YAML
Variables can take
author: Jane DoeDocuments
htmlpdf*docxodttypst**epubgfmPresentations
revealjspptxbeamer* This workshop focuses on PDF and Word outputs, which are most common for research papers, but most of what we cover applies to HTML as well. Different formats have slightly different options — see the Quarto Reference.
** Typst is a newer alternative to LaTeX for PDF outputs, and still developing. It is faster and requires no installation, but is less flexible for now.
Strings with special characters, such as colon, require quotation marks — single ’ or double ”
--- title: "Journals: A Mock Paper" subtitle: Prepared for a Quarto Workshop author: Jane Doe date: 4 March 2026 date-format: "D MMMM YYYY" format: pdf ------ title: "Journals: A Mock Paper" subtitle: Prepared for a Quarto Workshop author: Jane Doe date: 4 March 2026 date-format: "D MMMM YYYY" format: pdf ---
Quotation marks are optional for strings without special characters
date: 4 March 2026 becomes 2026-03-04 by defaultdate-format* defines how they should appear instead
date-format: "D MMMM YYYY" turns it into 4 March 2026date: today becomes the date on which the document is rendereddate: last-modified becomes the date on which the file was last modified* See quarto.org/docs/reference/dates.html for the date formats.
The thanks variable adds a note to the title
Notice that
The syntax ^[footnotes go here] adds footnotes to any string — in PDF and Word outputs
The abstract variable takes a longer string
---
title: "Journals: A Mock Paper"
author: Jane Doe
date: 4 March 2026
date-format: "D MMMM YYYY"
abstract: |
Why do some academic journals rank
higher than others on Google Scholar?
This paper introduces a new dataset on
the rankings of fictitious journals, and
uses it to explore what predicts their
impact.
format: pdf
---Notice that
The bibliography and csl variables take strings for file names
bibliography points to a .bib file
csl points to a .csl file
The strings for external files indicate where the files are, and how they are named
.qmd file
.. means one level upNotice that, as in R scripts, # starts a comment in YAML
format: and pdf:fontsize: 12pt# with spaces shown as dots
format:
··pdf:
····fontsize: 12pt
····linestretch: 1.5
The same document can be rendered into multiple formats
List all formats under format
The Render button renders the first format listed — here, pdf
Render MS WordOptions can be set for all formats, or for one format only
format, they apply to all formatsHere,
--- title: "Journals: A Mock Paper" number-sections: true format: pdf: linestretch: 1.5 docx: toc: true html: default ------ title: "Journals: A Mock Paper" number-sections: true format: pdf: linestretch: 1.5 docx: toc: true html: default ------ title: "Journals: A Mock Paper" number-sections: true format: pdf: linestretch: 1.5 docx: toc: true html: default ------ title: "Journals: A Mock Paper" number-sections: true format: pdf: linestretch: 1.5 docx: toc: true html: default ------ title: "Journals: A Mock Paper" number-sections: true format: pdf: linestretch: 1.5 docx: toc: true html: default ---
fontsize
11pt, 12ptlinestretch
1.5, 2geometry
margin=1inpapersize
a4, letternumber-sections
true or falsetoc
true or falselinkcolor, urlcolor, citecolor
blue, redlink-citations
true makes citations link to the list of references* The full list is available at quarto.org/docs/reference/formats/pdf.html.
date being indented, as if it was a sub-option of authorIn PDF outputs with numbered sections, a footnote in the title turns all headers into plain text
Note that
10:00
journals.qmd and fill in the YAML variables for the mock paper
reproduce_this.pdf and/or the slidesthanks for the note, including the author’s department, email, and websitenumber-sectionslinestretch, for the PDF outputjournals.qmd into Word
Multiple spaces on a given line are reduced to one
This is a sentence followed by four spaces. This is another sentence on the same line.
Line endings with fewer than two spaces are ignored
This is a sentence followed by one space. This is another sentence on a new line.
Two or more spaces at the end of a line introduce a hard break, forcing a new line
This is a sentence followed by two spaces.
This is another sentence on a new line.
A backslash \ does the same, and is easier to see, so it is less likely to be lost by accident
This is a sentence followed by a backslash.
This is another sentence on a new line.
Spaces on lines that start with a vertical line | are kept
Lines starting with the greater-than sign > introduce block quotes*
In God, we trust. All others must bring data.
— Anonymous
* Notice that three hyphens grouped together introduce an em-dash. Dashes are covered later on in this part.
One or more* blank lines introduce a new paragraph
This is the first sentence of a paragraph as it is preceded by a blank line. This is the
second sentence of that paragraph, which is followed by a blank line.
This is the first sentence of a new paragraph as it is preceded by a blank line. This is
the second sentence of that paragraph, which is followed by a blank line.This is the first sentence of a paragraph as it is preceded by a blank line. This is the second sentence of that paragraph, which is followed by a blank line.
This is the first sentence of a new paragraph as it is preceded by a blank line. This is the second sentence of that paragraph, which is followed by a blank line.
* Multiple blank lines between paragraphs reduce to one.
Text with the syntax <!-- comments --> is omitted from output
<!-- This paragraph needs re-writing -->
This is the first sentence of a paragraph as it is preceded by a blank line. This is the
second sentence of that paragraph, which is followed by a blank line.
This is the first sentence of a new paragraph <!-- I've removed italics --> as it is
preceded by a blank line. This is the second sentence of that paragraph.This is the first sentence of a paragraph as it is preceded by a blank line. This is the second sentence of that paragraph, which is followed by a blank line.
This is the first sentence of a new paragraph as it is preceded by a blank line. This is the second sentence of that paragraph.
05:00
reproduce_this.pdf, marked Ex. 7 in the marginjournals.qmd: paragraph 1reproduce_this.pdfjournals.qmd: block quote, between paragraphs 1 and 2; hypothesis 1, between paragraphs 14 and 15; hypothesis 2, between paragraphs 16 and 17The number sign # introduces headers; lower levels are created with additional signs
# Introduction becomes
Introduction
## Introduction becomes
Introduction
### Introduction becomes
Introduction
Notice that
number-sections: true in YAML# Abstract {.unnumbered}A pair of single asterisks * or underscores _ introduces italics
*italics* becomes italics
_italics_ becomes italics as well
A pair of double asterisks or underscores introduces bold
**bold** becomes bold
__bold__ becomes bold as well
These two rules can be combined
***bolditalics*** becomes bolditalics
**_bolditalics_** becomes bolditalics as well
A pair of double tildes introduces strikethrough
~~strikethrough~~ becomes strikethrough
Square brackets followed by a class in curly brackets introduce further styles*
[underline]{.underline} becomes underline
[small caps]{.smallcaps} becomes Small Caps
[highlighted]{.mark} becomes highlighted
* These are called spans. They work in HTML, PDF, and Word outputs. Some other classes are output specific.
03:00
reproduce_this.pdf
journals.qmdreproduce_this.pdf
journals.qmd: paragraph 2You can link text to existing headers in the same document
[Introduction](#introduction) becomes Introduction, and a click takes the reader to the section with the header # Introduction
Quarto creates these identifiers from headers automatically — in lower case, with hyphens instead of spaces
[Literature Review](#literature-review) becomes Literature Review
Alternatively, you can give headers your own identifiers
* Quarto offers a more powerful alternative for sections, as well as for figures, tables, and equations: cross-references, covered in Part 7.
You can link text to URLs
[visit my website](https://resulumit.com/) becomes visit my website
[https://resulumit.com](https://resulumit.com/) becomes https://resulumit.com
<https://resulumit.com> becomes https://resulumit.com as well
You can also link text to an email address
[email me](mailto:jane.doe@example.edu)* becomes email me
<jane.doe@example.edu> becomes jane.doe@example.edu
* Notice the prefix mailto: in the syntax.
03:00
reproduce_this.pdf
journals.qmd: paragraph 4reproduce_this.pdf
journals.qmd: thanks in YAMLInline equations go between a pair of single dollar signs $ — with no space between the signs and the equation itself
$E = mc^{2}$ becomes E=mc2
Block equations go between a pair of double dollar signs $$
$$E = mc^{2}$$ becomes
E=mc2
Notice that
For inline footnotes, use the ^[footnote] syntax
Jane Doe^[Corresponding author.] becomes Jane Doe1
1 Corresponding author.
Notice that
An alternative is to use the [^identifier] syntax, with identifiers defined elsewhere in the same document
Dr Doe holds a PhD in rock science.1
1 She defended her thesis in 2017.
Notice that
03:00
reproduce_this.pdfjournals.qmd: paragraph 22; block equation, between paragraphs 22 and 23reproduce_this.pdfjournals.qmd: paragraph 3Lines starting with an asterisk *, a plus +, or a minus - sign introduce lists*
Lists can be nested within each other, with indentation
* Lists need a blank line before them, unless they follow another list item.
List items can be numbered
Note that
1., 1., 1. would still become 1, 2, 3Two hyphens grouped together introduce an en-dash
-- becomes –
Three hyphens grouped together introduce an em-dash
--- becomes —
A pair of tildes introduces subscript
CO~2~ becomes CO2
A pair of carets introduces superscript
R^2^ becomes R2
Note that
R^2^ versus $R^{2}$03:00
reproduce_this.pdfjournals.qmd: list, between paragraphs 10 and 11reproduce_this.pdfjournals.qmd: paragraph 6reproduce_this.pdfjournals.qmd: paragraph 5The {{< pagebreak >}} shortcode* introduces a page break
Note that
\newpage, which works in PDF outputs only* Shortcodes are special Quarto commands, written between {{< and >}}. Others include, e.g., {{< lipsum >}} for placeholder text.
Three or more colons ::: introduce divs, which group content and give it a style
Note
This dataset is fabricated, for demonstration purposes only.
02:00
reproduce_this.pdf — the Introduction starts on a new pagejournals.qmd: before header 2, the Introduction.bib files*
.bib files are specified with the bibliography variable in YAML
[references.bib, packages.bib].bib file
* Other formats are possible too, e.g., CSL JSON.
@article, @bookbennett2015title, author@article{bennett2015, title = {Peanut Butter and Jelly}, author = {Bennett, Sam}, journal = {Journal of Bone}, year = {2015}, volume = {1}, number = {12}, pages = {3--35} }@article{bennett2015, title = {Peanut Butter and Jelly}, author = {Bennett, Sam}, journal = {Journal of Bone}, year = {2015}, volume = {1}, number = {12}, pages = {3--35} }@article{bennett2015, title = {Peanut Butter and Jelly}, author = {Bennett, Sam}, journal = {Journal of Bone}, year = {2015}, volume = {1}, number = {12}, pages = {3--35} }@article{bennett2015, title = {Peanut Butter and Jelly}, author = {Bennett, Sam}, journal = {Journal of Bone}, year = {2015}, volume = {1}, number = {12}, pages = {3--35} }@article{bennett2015, title = {Peanut Butter and Jelly}, author = {Bennett, Sam}, journal = {Journal of Bone}, year = {2015}, volume = {1}, number = {12}, pages = {3--35} }
Cite -> BibTeX, copy, paste into the .bib file, edit if necessary, and saveCite this article or Export citation.bib files up to date
Visual mode can find references, e.g., by DOI, and add them to the .bib file — but recall the warning in Part 2toBibtex(citation("modelsummary")) in the Console, copy the entry, and paste it into the .bib file.bib fileCite this repository -> BibTeX on the repository page.csl files
.csl file, and for the style therein, to format citations and references
.csl files are specified with the csl variable in YAML.csl files affect the style only in outputs
.qmd documents remains the sameAll citation keys take the ‘at’ sign @, while square brackets and/or minus signs introduce variation
[@bennett2015] becomes (Bennett, 2015)
@bennett2015 becomes Bennett (2015)
[-@bennett2015] becomes (2015)
[@bennett2015, 35] becomes (Bennett, 2015, p. 35)
[@bennett2015, 33-35] becomes (Bennett, 2015, pp. 33–35)
[@bennett2015, ch. 1] becomes (Bennett, 2015, ch. 1)
[@bennett2015; @gilbert2019] becomes (Bennett, 2015; Gilbert, 2019)
[see @bennett2015, for details] becomes (see Bennett, 2015, for details)
@bennett2015 [33-35] becomes Bennett (2015, pp. 33–35)
* Specifically, the outputs on this slide are formatted according to the APA 7th edition.
All citation keys take the ‘at’ sign @
A clever sentence [@bennett2015]. becomes A clever sentence [1]. in, e.g., IEEE
A clever sentence [@bennett2015; @gilbert2019]. becomes A clever sentence [1], [2].
Individual styles may or may not use additional information, such as page numbers
A clever sentence [@bennett2015, 35]. becomes A clever sentence [1, p. 35]. in IEEE
Individual styles may or may not be sensitive to variation, such as square brackets
A clever sentence @bennett2015. becomes A clever sentence [1]. in IEEE as well
The list of references is placed at the end of the document, without a header
.qmd document with a header of your choice, e.g., # Referencesreference-section-title: References in YAML, which is never numberedThis is the last sentence of an APA style manuscript.
References
Bennett, S. (2015). Peanut butter and jelly. Journal of Bone, 1(12), 3–35.
Gilbert, T. (2019). Turning wine into water. In M. Albert (Ed.), The book of ground (pp. 124–142). Antman.
To place the list elsewhere — e.g., before an appendix — use a div with the identifier refs
This is the last sentence of an APA style manuscript.
References
Bennett, S. (2015). Peanut butter and jelly. Journal of Bone, 1(12), 3–35.
Gilbert, T. (2019). Turning wine into water. In M. Albert (Ed.), The book of ground (pp. 124–142). Antman.
Appendix
This is the first sentence of the appendix.
For links from in-text citations to the reference list, set link-citations: true in YAML
a click on these links takes the reader to the relevant entry in the list
in PDF outputs, the citecolor variable sets the colour of these links
nocite includes references in the list without citing them in text
07:30
references.bib for the following article
10.1073/pnas.0507655102references.bib and apa_7th.csl to the YAMLreproduce_this.pdfjournals.qmd: paragraphs 7 to 9.csl file for your favourite style from zotero.org/styles, into the manuscript folderTerminalNote that
@citation-keys.Rmd document needs little conversion
Most code goes inside code chunks
Code can also go in line with text
rThe first item in code chunks indicates the engine to run the code
r is the specified engine, indicating that the code in the chunk above should be run by R
pythonjupyter: python3 in YAMLknitr, via the reticulate package (Ushey et al. 2025)It is recommended, but optional, to label the code chunks
fig- for figures and tbl- for tables — covered in Part 7Code chunks can take further options
include option is set to false
true and false in lower caseThe R Markdown syntax for options continues to work*
* Notice that dots in option names become hyphens, e.g., fig.cap becomes fig-cap.
Options have default values
echo, the default is true
echo: should the code be shown in the output?true: yes, it shouldThis chunk prints two things in the output document — (a) the code, on a grey background, and (b) its result, as plain text
Setting echo: false prevents the code from being displayed in the output document
name origin branch h5_index h5_median
Journal of Bears Americas Physical 73 97
Journal of Moon Asia Social 72 106
Journal of Lumber Americas Physical 72 100
Journal of Houses Europe Social 72 102
Journal of Water Europe Social 70 100
Journal of Jeans Americas Physical 69 101
Setting output: false prevents the result from being displayed in the output document
head(df[, 1:5])
Setting output: asis passes the results as they are produced by the code
Prevent R from running the code in the chunk altogether
Prevent messages, warnings, and/or errors from being displayed in the output
Cache results for future renders
journals_cache, next to your documentDefine the actual dimensions of figures, in inches
Define the size of figures as they appear in the output document
Define the alignment, caption, and resolution of figures
Options can be set for all chunks at once, in YAML, with execute
#| echo: true in a chunk whose code you would like to showecho: false
.qmd file, for reproducibilityIt is recommended to use the first code chunk for general setup
setup, which has a special meaning in RStudio
df_raw, unchanged, to be cleaned laterIt is recommended to use the second code chunk for the main operations on raw data
datadf, so that df_raw remains unchanged```{r} #| label: data #| include: false df <- df_raw |> mutate(subfield = as.factor(subfield), english = as.factor(english), age = 2026 - since) |> select(-since) ``````{r} #| label: data #| include: false df <- df_raw |> mutate(subfield = as.factor(subfield), english = as.factor(english), age = 2026 - since) |> select(-since) ``````{r} #| label: data #| include: false df <- df_raw |> mutate(subfield = as.factor(subfield), english = as.factor(english), age = 2026 - since) |> select(-since) ```
You do not need to render the whole document to test your code
Ctrl + Enter (Windows) or Cmd + Enter (Mac)setup chunk runs first, automatically, if it has not been run yetEnvironment, for any objects the code createsCode can also be incorporated in text, with the `{r} ` syntax*
* The R Markdown syntax for inline code, `r `, continues to work as well.
If we multiply pi by 5, we get 15.7079633.
The average H5 Index for the journals in the dataset is 26.3611366, which would round to 26.4.
Only 113 journals in the dataset are published in a language other than English.
07:30
dplyr, ggplot2, and modelsummary, and imports raw dataexecute in YAMLsubfield and english into factorsage, based on sincesince from the data framereproduce_this.pdf — i.e., 1091 observations, and 4.68 issues per yearjournals.qmd: paragraphs 21 and 23 — hint: use the nrow() and mean() functionsExisting images can be added with Markdown syntax, or with code
Figures can also be created with code, inside code chunks
The syntax  embeds images produced elsewhere*
.qmd fileAttributes, such as width and fig-align, go in curly brackets after the image
Note that fig-align works only for figures narrower than the page, e.g., with width="20%"
knitrThe knitr package offers an alternative, with the include_graphics() function
fig-capNotice that
package::function(), without loading the packageout-width or out-height, rather than fig-width and fig-height03:00
reproduce_this.pdf: figure 1journals.qmd: figure 1, between paragraphs 19 and 20ggplot2 | Overviewggplot2 communityggplot2 | BasicsFigures with ggplot2 are built from three basic components
ggplot() function and the data argument
ggplot() functionggplot() functionggplot2 | ChunkPut the code in a chunk, and give it a label and a caption
ggplot2 | FacetsAdd facets for subgroups, e.g., branch
ggplot2 | LegendScale the colour to improve the legend
```{r}
#| label: fig-journals
#| fig-cap: "A scatterplot of journal metrics."
ggplot(data = df, mapping = aes(x = h5_median,
y = h5_index,
color = subfield)) +
geom_point() +
facet_wrap(~ branch) +
scale_colour_discrete(name = "Journal Type",
breaks = c(0, 1),
labels = c("Generalist", "Subfield"))
```ggplot2 | Theme and LabelsChange the theme, and improve the axis labels
```{r}
#| label: fig-journals
#| fig-cap: "A scatterplot of journal metrics."
ggplot(data = df, mapping = aes(x = h5_median,
y = h5_index,
color = subfield)) +
geom_point() +
facet_wrap(~ branch) +
scale_colour_discrete(name = "Journal Type",
breaks = c(0, 1),
labels = c("Generalist", "Subfield")) +
theme_bw() +
labs(x = "H5 Median", y = "H5 Index")
```ggplot2 | Notesgeom_point() is one of many geoms available
geom_bar() for bar chartsgeom_boxplot() for box and whiskers plots#| layout-ncol: 2 in a chunk that produces two figures#| fig-pos: "H" keeps them where they are in the text10:00
reproduce_this.pdf: figure 2journals.qmd: figure 2, between paragraphs 21 and 22reproduce_this.pdf: figure 3journals.qmd: figure 3, between paragraphs 27 and 28Hand-made tables can be added with Markdown syntax
Tables can also be produced with code, inside code chunks
The following syntax, outside code chunks, introduces tables that Quarto can recognise
| First Column | Second Column |
|---|---|
| First cell | First cell |
| Second cell | Second cell |
| Third cell | Third cell |
Notice that
Colons in the separator line define the alignment of columns
| Left-aligned | Center-aligned | Right-aligned |
|---|---|---|
| 1 | 2 | 3 |
| 11 | 22 | 33 |
| 111 | 222 | 333 |
Note that
Table -> Insert Table, can help, but switching to it rewrites the whole document05:00
reproduce_this.pdf: table 1journals.qmd: table 1, between paragraphs 11 and 12Tables can also be produced with code, in chunks
modelsummary, tinytable, gt, kableExtra, flextablemodelsummary (Arel-Bundock 2022)
Table the first four rows of the dataset, with datasummary_df()
Notice that
tbl-cap chunk optionknitr::kable() is an alternative| name | origin | branch | h5_index | h5_median | english | subfield | issues | age |
|---|---|---|---|---|---|---|---|---|
| Journal of Bears | Americas | Physical | 73.00 | 97.00 | 1 | 1 | 7.00 | 67.00 |
| Journal of Moon | Asia | Social | 72.00 | 106.00 | 1 | 0 | 6.00 | 70.00 |
| Journal of Lumber | Americas | Physical | 72.00 | 100.00 | 1 | 1 | 8.00 | 36.00 |
| Journal of Houses | Europe | Social | 72.00 | 102.00 | 1 | 0 | 8.00 | 44.00 |
Create a table of summary statistics with datasummary_skim()
Notice that
| Unique | Missing Pct. | Mean | SD | Min | Median | Max | Histogram | |
|---|---|---|---|---|---|---|---|---|
| h5_index | 69 | 0 | 26.4 | 13.8 | 1.0 | 24.0 | 73.0 | |
| h5_median | 100 | 0 | 39.4 | 21.3 | 3.0 | 35.0 | 109.0 | |
| issues | 10 | 0 | 4.7 | 1.8 | 1.0 | 4.0 | 12.0 | |
| age | 127 | 0 | 48.9 | 26.4 | 7.0 | 44.0 | 164.0 |
Choose the statistics as well as variables yourself with datasummary()
Notice that
rows ~ columns| N | Mean | SD | Min | Max | |
|---|---|---|---|---|---|
| h5_index | 1091 | 26.36 | 13.81 | 1.00 | 73.00 |
| h5_median | 1091 | 39.40 | 21.27 | 3.00 | 109.00 |
| issues | 1091 | 4.68 | 1.79 | 1.00 | 12.00 |
| age | 1091 | 48.90 | 26.37 | 7.00 | 164.00 |
Rename the variables, in the formula*, with backticks ` around names with spaces
| N | Mean | SD | Min | Max | |
|---|---|---|---|---|---|
| H5 Index | 1091 | 26.36 | 13.81 | 1.00 | 73.00 |
| H5 Median | 1091 | 39.40 | 21.27 | 3.00 | 109.00 |
| Issues | 1091 | 4.68 | 1.79 | 1.00 | 12.00 |
| Age | 1091 | 48.90 | 26.37 | 7.00 | 164.00 |
* When using datasummary_skim(), rename the variables while selecting them, e.g., select(df, `H5 Index` = h5_index).
07:30
reproduce_this.pdf: table 2, and the table in the appendixjournals.qmd: table 2, between paragraphs 23 and 24datasummary_skim(df), for now at the end of the documentCreate a table of regression models with modelsummary()
Keep only a selection of statistics, with gof_map
Display multiple models in the same table, in a named list
| Model 1 | Model 2 | |
|---|---|---|
| (Intercept) | 17.415 | 4.226 |
| (1.137) | (1.415) | |
| issues | 1.913 | 1.424 |
| (0.227) | (0.212) | |
| english1 | 17.262 | |
| (1.244) | ||
| Num.Obs. | 1091 | 1091 |
| R2 | 0.061 | 0.202 |
Change variable labels, with coef_rename
| Model 1 | Model 2 | |
|---|---|---|
| Constant | 17.415 | 4.226 |
| (1.137) | (1.415) | |
| Issues | 1.913 | 1.424 |
| (0.227) | (0.212) | |
| English | 17.262 | |
| (1.244) | ||
| Num.Obs. | 1091 | 1091 |
| R2 | 0.061 | 0.202 |
Add significance stars, with stars
| Model 1 | Model 2 | |
|---|---|---|
| * p < 0.05, ** p < 0.01, *** p < 0.001 | ||
| Constant | 17.415*** | 4.226** |
| (1.137) | (1.415) | |
| Issues | 1.913*** | 1.424*** |
| (0.227) | (0.212) | |
| English | 17.262*** | |
| (1.244) | ||
| Num.Obs. | 1091 | 1091 |
| R2 | 0.061 | 0.202 |
modelsummary() include, e.g.,
notes, for notes below the tableestimate and statistic, for what is shown, e.g., confidence intervals rather than standard errorsoutput, to save the table as a file, e.g., output = "table.docx"glm(), fixest::feols(), lme4::lmer()07:30
reproduce_this.pdf: table 3journals.qmd: table 3, between paragraphs 30 and 31With the content of the paper in place, this part covers some finishing touches
Labels start with a prefix that indicates the type of the target
| Target | Label prefix | Example label | In text | Becomes |
|---|---|---|---|---|
| Figure | fig- |
#fig-scatter |
@fig-scatter |
Figure 1 |
| Table | tbl- |
#tbl-regression |
@tbl-regression |
Table 1 |
| Equation | eq- |
#eq-model |
@eq-model |
Equation 1 |
| Section | sec- |
#sec-results |
@sec-results |
Section 3 |
Note that
[-@fig-scatter] drops the prefix, as [-@key] drops the authornumber-sections: true in YAMLFor images, add the label in curly brackets, after the image
Figure 1 shows the Google Scholar homepage.
Notice that
For figures produced by code, add a label starting with fig- and a caption
Figure 1 visualises the relationship between the two journal metrics.
For Markdown tables, add the label in curly brackets, after the caption
See Table 1 for further details.
For tables produced by code, add a label starting with tbl- and a caption
Table 1 provides results from two OLS models.
07:30
journals.qmdreproduce_this.pdfjournals.qmd: paragraphs 19, 21, and 27reproduce_this.pdfjournals.qmd: paragraph 11journals.qmdreproduce_this.pdfjournals.qmd: paragraphs 23 and 29For equations*, add the label in curly brackets, after the closing dollar signs
E=mc2(1)
According to Equation 1, space and time are linked.
* Only block equations, with double dollar signs, can be cross-referenced.
For sections, add the label in curly brackets, after the header
As discussed in Section 2, …
Note that
number-sections: true in YAMLSpecific results in tables can be referred to as well
In Model 1, the coefficient for Issues is 1.91.
Note that
summary(lm1)$coefficients
summary(lm1)$coefficients["issues", "Std. Error"]05:00
reproduce_this.pdfjournals.qmd: paragraph 29reproduce_this.pdfjournals.qmd: paragraph 22Some content suits one output format, but not others
content-visible or content-hidden classes, with when-formatAppendices are often numbered separately, e.g., as pages A1, A2, …, and Figure A1
{=latex} passes the content on to PDF outputs only{=html} is for HTML outputs onlyManuscripts often list the authors’ affiliations and emails in notes to their names
thanks adds a note to the title onlyemail, are not printed\thanks{} in the author string
\href{}{}, as Markdown does not work within LaTeXSome LaTeX code requires packages, e.g., pdflscape for landscape pages, often used for wide tables
include-in-header, under the pdf format
07:30
reproduce_this.pdf#| tbl-pos: "H" to its chunkreproduce_this.pdf* Often also by multiple authors, covered in Part 9, and/or on different computers.
Typically, hand-made attempts to version control lead to cluttered folders
manuscript/
|
|- journals_FINAL_19May.qmd
|- journals_FINAL.qmd
|- journals_FINAL_FINAL_v2.qmd
|- journals_26APRIL_newliterature.qmd
|- journals_Jane_comments.qmd
|
...
|
|- references.bib
|- apa_7th.csl
Each commit is a snapshot of the repository, linked to the previous one
Notice that
C1, C2, and C3 are three commits, made one after anotherHEAD marks the commit you are currently working on, typically the latest oneGit tabusethis and gitcreds
* Alternatively, Git and GitHub can be used by typing commands in the Terminal, e.g., git commit, or with other apps, e.g., GitHub Desktop.
Initial setup involves seven steps*
usethis package (Wickham et al. 2025)
maingitcreds package (Csárdi 2024)* We have started this process already, in Part 1, by installing Git and signing up for GitHub.
Tools -> Global Options -> Git/SVN
Enable version control interface for RStudio projects is tickedGit executable shows a path to Git
C:/Program Files/Git/bin/git.exe on Windows, /usr/bin/git or /opt/homebrew/bin/git on MacBrowse... to find it, and restart RStudioTools -> Global Options -> Terminal -> New terminals open withConsole
pull.rebase, which tells Git how to combine your commits with those of co-authors
Console
Generate tokenConsole
Replace these credentials* For details, and for troubleshooting, see happygitwithr.com/https-pat (Bryan et al. 2024).
Console
mainCan't get user information for this token, GitHub does not accept your token
GitHub API error (401): Bad credentialsReplace these credentialsThere are two ways to set up a project with Git and GitHub
yourname-quarto — covered nextusethis functions, as in initial setupConsole
After restarting, observe that
Git tab in RStudio
.gitignore file
ConsoleObserve that
https://github.com/USER_NAME/REPOSITORY_NAMEusethis::use_git()private = FALSE would make it publicThe Git tab in RStudio lists the files that are new, or have changed, since the last commit
Status shows how they have changed
Staged checkboxes select the changes for the next commitThe buttons on the Git tab do what Git commands would otherwise do in the Terminal
| Button | Does | Equivalent command* |
|---|---|---|
Staged checkbox |
selects changes for the next commit | git add |
Diff |
shows the changes, line by line | git diff |
Commit |
records the staged changes, with a message | git commit |
Pull |
brings the changes from GitHub | git pull |
Push |
sends the commits to GitHub | git push |
History |
lists past commits, and what they changed | git log |
| Branch menu | creates, and switches between, branches | git branch, git switch |
* You do not need to know the commands to use Git in RStudio, but they help with searching for solutions online.
journals.qmd, and save itGit tab, with M as StatusCommit, which opens a new windowStaged for one or more files that you would like to commitCommit message that summarises the changesCommit, to create a record of the new version locally, on your computerPush, to send the commit to GitHubGit tab in RStudio, and on GitHubNotice that
C1 is the initial commit, C2 the one that deleted the sentenceClick History on the Git tab to see all past commits
View file @ ... to see a file as it was at that commitNote that
History shows committed versions onlyGit tab insteadUndoing changes depends on whether they are committed
Git tab
Revert..., in the gear (More) menuHistory
View file @ ... and Save As, then commitHistory, select the first commit, C1, and then journals.qmdView file @ ..., and then Save As, replacing the current journals.qmdM on the Git tabNotice that
C2, but adds a new commit, C3There are good reasons to exclude some files from version control, including files
journals.pdf, as opposed to journals.qmd.gitignoreRecall that usethis::use_git() has created a .gitignore file, in the main folder of the project
journals.pdf*.pdf
.Rproj.user, .RhistoryFiles pane, and typing them in.gitignore | PatternsYou can ignore, for example,
a specific folder, relative to the main folder
a specific file in a specific folder
a specific file in any folder
all files with a specific extension, anywhere in the project
all folders ending with a specific suffix, anywhere
.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/.Rproj.user .Rhistory .RData .Ruserdata /data/raw/ /manuscript/journals.pdf journals.pdf *.pdf *_cache/
.gitignore | NotesTo ignore a file that is already tracked, adding it to .gitignore is not enough
.gitignore, as usualTerminal*
git rm --cached manuscript/journals.pdf* This is the only Git command in this workshop that requires the Terminal.
05:00
filter() function in the data chunkjournals.qmd
journals.pdf, journals.docx.gitignore works as intendedpull.rebase = "false" in Part 8The owner’s setup involves two steps
Console
Settings -> Collaborators -> Add people10:00
File -> New Project -> Version Control -> Git, with the repository address ending in .gitPull before you start, push when you finish
Pull, with Pull on the Git tab
Already up to dateEdit, save, commit, and push — as in Part 8, for a single author
Pull and push frequently
05:00
journals.qmd, one person at a time
author can take a list, as in Part 3Notice that you should not have encountered any errors or merge conflicts
10:00
journals.qmd, all at the same time
Notice that you have encountered an error, but not a merge conflict
10:00
journals.qmd, at the same time
Notice that you have encountered not only an error, but also a merge conflict
<<<<<<< HEAD=======05:00
* Quarto can do this automatically, with editor: markdown: wrap: sentence in YAML — but only in Visual mode, which rewrites the whole document, as noted in Part 2. Formatters such as panache do the same, but need to be installed separately.
mainA branch is a parallel line of development in a repository
mainjane-edits below, with C4, while main continues with C3A pull request is a proposal to merge a branch into another, e.g., into main
C5 below, the merge commit, which combines the changes from both branchesThe workflow with branches involves four steps, two of which are new
New Branch button on the Git tab
main remains unchangedCompare & pull request, and write a note to the ownermain, from the branch menu on the Git tab, and pull
10:00
journals.qmd, save, commit, and push
mainmain, pull, and observe the editsjournals.qmd, with the pencil iconmain, or proposed as a pull request05:00
journals.qmd, on GitHub
main; collaborators create a pull request_extensions folder, in the same folder as the Quarto documentTo install an extension, move into the folder of your document first, e.g., manuscript
TerminalConsole, with the quarto packageNotice that
cd and setwd() move into the folder of the document; setwd("..") moves backGitHubUsername/RepositoryName needs to be replaced with the repository of the extensionAdd the format to the folder of the document
Console, as on the previous slideThen adjust the YAML, following the README and the template of the extension on GitHub
jss-pdfTo start a new article with a journal format, run the following in the Console
new_manuscript_extensions/, with the format itselfnew_manuscript.qmd, an example article, named after the folderbibliography.bib, and other example filesQuarto has a standard way of listing authors*
name
email, orcid, correspondingid
ref---
title: "Journals: A Mock Paper"
author:
- name: Jane Doe
email: jane.doe@example.edu
orcid: 0000-0000-0000-0000
corresponding: true
affiliations:
- ref: exu
- name: John Roe
email: john.roe@example.org
affiliations:
- ref: exu
- name: Example Institute
affiliations:
- id: exu
name: Example University
department: Department of Science
format: jss-pdf
---* See quarto.org/docs/journals/authors.html for all the options, e.g., url, note, equal-contributor.
10:00
journals.qmd, named journals_jss.qmd, in the same foldermanuscript folder
jss-pdf, or that of your chosen formatA _quarto.yml file, in the main folder, turns the folder into a Quarto project*
The type of a project* determines what Quarto builds from its documents
default: each document on its own, as so farbook: chapters combined into one document
website: documents turned into the pages of a website
* See quarto.org/docs/books and quarto.org/docs/websites.
Settings on GitHub, as it is private so farquarto publish puts HTML outputs online, e.g., on GitHub Pages or Quarto PubREADME.md file
Congratulations for making it this far, and thank you for joining me!