+ - 0:00:00
Notes for current slide
Notes for next slide

Managing Citation In R Bookdown

with Zotero

Lin Yu

University of Alberta

2021/07/31

1 / 14

Get Started

2 / 14

Create R Bookdown Project

If you do not have a R bookdown project yet, you will need to build one first.

3 / 14

Create R Bookdown Project

If you do not have a R bookdown project yet, you will need to build one first.

Create a new R bookdown1 project from the menu File - New Project -> New Directory -> Book Project using bookdown

  • The contents of the book are wrote with R markdown, by default, the name of each R markdown file has the following format: chapter number and chapter title. For example, 01_introduction.
3 / 14

Create R Bookdown Project

If you do not have a R bookdown project yet, you will need to build one first.

Create a new R bookdown1 project from the menu File - New Project -> New Directory -> Book Project using bookdown

  • The contents of the book are wrote with R markdown, by default, the name of each R markdown file has the following format: chapter number and chapter title. For example, 01_introduction.

  • The bibliographies are stored in the .bib file(s), in this case, book.bib and packages.bib.

3 / 14

Create R Bookdown Project

If you do not have a R bookdown project yet, you will need to build one first.

Create a new R bookdown1 project from the menu File - New Project -> New Directory -> Book Project using bookdown

  • The contents of the book are wrote with R markdown, by default, the name of each R markdown file has the following format: chapter number and chapter title. For example, 01_introduction.

  • The bibliographies are stored in the .bib file(s), in this case, book.bib and packages.bib.

[1] See the official tutorial for more details

3 / 14

Have Zotero ready

Install Zotero is quite simple, so I decided to skip this part:)

4 / 14

Better-bibtex extension

5 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

6 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

  • Go to Tools on Zotero's main menu. Then click on Add-ons, select ‘Extensions’
6 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

  • Go to Tools on Zotero's main menu. Then click on Add-ons, select ‘Extensions’

  • Click on the gear in the top-right corner and choose ‘Install Add-on From File…’

6 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

  • Go to Tools on Zotero's main menu. Then click on Add-ons, select ‘Extensions’

  • Click on the gear in the top-right corner and choose ‘Install Add-on From File…’

  • Choose .xpi file that you have just downloaded, click ‘Install’

6 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

  • Go to Tools on Zotero's main menu. Then click on Add-ons, select ‘Extensions’

  • Click on the gear in the top-right corner and choose ‘Install Add-on From File…’

  • Choose .xpi file that you have just downloaded, click ‘Install’

  • Restart Zotero

6 / 14

better-bibtex addin

After downloading Zotero, you need to install the 'better-bibtex' extension, which help create citekeys for your bibliographies. Here is where you can get the better-bibtex addin. then

  • Go to Tools on Zotero's main menu. Then click on Add-ons, select ‘Extensions’

  • Click on the gear in the top-right corner and choose ‘Install Add-on From File…’

  • Choose .xpi file that you have just downloaded, click ‘Install’

  • Restart Zotero

You can customize the format of citekey as you like:)

  • You can think of the citekey as the name or identifier of the bibliography

  • The citekey is used in R markdown files for citation

6 / 14

How to Cite?

In R markdown, there are a few different ways to cite a bibliography.:

7 / 14

How to Cite?

In R markdown, there are a few different ways to cite a bibliography.:

The simplest method is to use the visual mode's insert citation option.

  • Swith to the visual mode, then you can find the insert button, where you can click on citation
7 / 14

How to Cite?

In R markdown, there are a few different ways to cite a bibliography.:

The simplest method is to use the visual mode's insert citation option.

  • Swith to the visual mode, then you can find the insert button, where you can click on citation

Alternatively, use insert citation addin in the citr R pacakge

  • why?: You may prefer source mode; you do not have visual mode in your current R environment.

  • install citr package (you may want to use devtools::install_github("crsh/citr"))

  • afte installation, you can find it in the Addins, and you can even define a keyboard shortcut to call the addin.

7 / 14

How to Cite?

In R markdown, there are a few different ways to cite a bibliography.:

The simplest method is to use the visual mode's insert citation option.

  • Swith to the visual mode, then you can find the insert button, where you can click on citation

Alternatively, use insert citation addin in the citr R pacakge

  • why?: You may prefer source mode; you do not have visual mode in your current R environment.

  • install citr package (you may want to use devtools::install_github("crsh/citr"))

  • afte installation, you can find it in the Addins, and you can even define a keyboard shortcut to call the addin.

7 / 14

How to Cite? (Continued)

The third method for citation:

8 / 14

How to Cite? (Continued)

The third method for citation:

Manually export bibliographies into the R project.

  • Export the collection as Better BibTex format, put the .bib file under the root directory of the R bookdown project;

  • in the R markdown file, use syntax \cite{@citekey} to cite

  • Not recommended: (i) you need to manually update the .bib file (ii) using \cite{@citekey} is not efficient

8 / 14

Almost there:)

9 / 14

One Last Step

10 / 14

One Last Step

Change the bibliography setting in the index.Rmd file: (see below codes)

documentclass: book
bibliography: [YOUR_REFERENCE.bib]

If you use the insert citation option, then .bib file with a defualt name of "reference.bib" will be generated and updated every time you add new citations.

10 / 14

One Last Step

Change the bibliography setting in the index.Rmd file: (see below codes)

documentclass: book
bibliography: [YOUR_REFERENCE.bib]

If you use the insert citation option, then .bib file with a defualt name of "reference.bib" will be generated and updated every time you add new citations.

You are all set now! The default citation style is (author year)

However, you can change the citation style as you like!

10 / 14

Change Citation Style

Two easy steps are required if you want to change the citation style:

11 / 14

Change Citation Style

Two easy steps are required if you want to change the citation style:

Step 1: Download .csl file

  • Download the desired .csl file (e.g., the-lancet.csl), .csl file can be downloaded from the Zotero Style Repo, then you need to store it under the root directory of the R bookdown project

  • A trick here: by default, the .csl file will be downloaded to the Zotero folder.

11 / 14

Change Citation Style

Two easy steps are required if you want to change the citation style:

Step 1: Download .csl file

  • Download the desired .csl file (e.g., the-lancet.csl), .csl file can be downloaded from the Zotero Style Repo, then you need to store it under the root directory of the R bookdown project

  • A trick here: by default, the .csl file will be downloaded to the Zotero folder.

Step 2: modify index.Rmd and _output.yml

  • comment the biblio-style and specify the csl as follow:
bibliography: [book.bib, packages.bib,testbib.bib, references.bib]
#biblio-style: apalike
csl: the-lancet.csl
  • add pandoc_args: [ "--csl", "the-lancet.csl" ] to the _output.yml (see next page)
11 / 14

Change Citation Style (Cont'd)

  • add pandoc_args: [ "--csl", "the-lancet.csl" ] to the _output.yml (see next page)
bookdown::gitbook:
css: style.css
pandoc_args: [ "--csl", "the-lancet.csl" ]
config:
toc:
before: |
<li><a href="./">A Minimal Book Example</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: default
pandoc_args: [ "--csl", "the-lancet.csl" ]
keep_tex: yes
bookdown::epub_book:
pandoc_args: [ "--csl", "the-lancet.csl" ]
12 / 14

I am so happy

13 / 14

Thank you

14 / 14

Get Started

2 / 14
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow