Previously

A brief reminder.

Plain vs. enhanced text

Simple text. No editing, no hyperlinks, no enhanced fields.

Enhanced text integrates r-code.

This is an example of how automatization can be implemented in the work flow. 
My list of movies include `r nrow(dfmv)` entries. 
The title of those movies are `r dfmv$Movie`. 
Is there a movie that I actually dont like on that list, well, the answer is that I dislike exactly 
`r dfmv %>% filter(Like %in% c("No","no","NO")) %>% nrow()`
movies on that list.

Knit with parameters

# specify parameter in yaml header
title: "example"
output: html_document
date: "2024-05-09"
params:
  actor:
    label: "Actor"
    value: "Keanu Reeves"
    input: select
    choices: ["Keanu Reeves", "Alec Baldwin","Arnold Schwarzenegger"]
    multiple: yes
# assign parameter to object
actor<-params$actor
# use parameter in code
tmptbl<-dfmv %>% 
  filter(Actor %in% actor)

Quarto

Retains all the functions of a RMarkdown document while it enhances and simplifies the work flow further.

Quarto

Integrates more programming languages and makes it easier to use css, latex formatting directly in the source document .qmd.

Basically, Quarto makes it much much much easier for everyone to create presentations, live documents, websites, books and so on.

It can integrate shiny features too.

Quarto

Workflow in quarto

Workflow in quarto

Quarto

What we need to focus on is the .qmd.

flowchart LR
  A(Plain text) --> Z{.qmd}
  B(Code) --> Z{.qmd}
  C(Images) --> Z{.qmd}
  D(External source file) --> Z{.qmd}
  E(Formatting source file) --> Z{.qmd}
  F(...) --> Z{.qmd}

Elements that an .qmd file can integrate

Quarto

Similar to the RMarkdown set up.

1 - r

2 - RStudio

3 - Quarto, which can be downloaded https://quarto.org/docs/get-started/

After you’ve successfully installed r, RStudio, and quarto on your computer, we can start with creating websites and books.

Website

Self-publishing online using r is one way to integrate varying work-routines towards a greater goal – that of communicating own research, consultancy job involving data science, to name just a few examples.

Website

Create quarto website project

Default quarto website

.qmd, .yml, .css as well as a folder “_site”.

Render

A quarto website must be rendered first. This creates .html files inside the _site subfolder.

The index.html indexes the website. Brings everything together.

Live preview by typing in the Terminal:

quarto preview

Render by typing in the Terminal:

quarto render

The files

Virtually identical to .Rmd.

.yml file is for the entire website.

yaml header inside .qmd is for that .qmd only!

Listing all the individual pages

Remember to list in the navbar all the individual pages you’d like to be rendered in the final website. Otherwise, the website will not contain them!

Called inside the .yaml file.

The default .css file is empty.

.css stands for Cascade Style Sheets and is a language used most typically for styling HTML files.

Custom css

One can create custom css styles for their website or use pre-defined templates from the Internet.

Always be careful what you download from the Internet.

Create website content

Use the knowledge from previous sessions and create content for your website. Or, a basic structure that you could edit at a later stage.

Website content

Use data

Use data Stanciu et al. (2017) to integrate graphs and tables.

Use the Excel sheet movies.xlsx to integrate external source material.

Add pages

Create multiple pages that define a structure to the information you’d want to communicate.

For example: News, About, Education, Work experience.

Deploy website

First, quarto preview the website locally and make sure all is good.

Deploy website

We should think how we want to deploy the website, via quartopub.com or GitHub.

We can deploy directly from Terminal to quartopub.com using

quarto render

then

quarto publish quarto-pub

Account on quartopub.com

Make sure you have an account open on https://quartopub.com/.

Deploy website – GitHub

To publish the website via GitHub, we’d need to initiate git first. This will allow us to communicate with the online repository.

git init

Create an empty repository on your GitHub account. Then, connect the local repository to the newly created online repository.

remote add origin git@github.com:{your github user}/{your repository where the website will be hosted}.git

We will deploy the website by rendering it to a sub-folder docs.

To do this we need to modify the _quarto.yml document.

Open the .yml file, copy the following line and paste it as a sub-element to “project”.

This new line should be intended and be aligned with the “type: website” element! Save and close the .yml file.

output-dir: docs

Create a .nojekyll file to the repository. Explanation is given https://quarto.org/docs/publishing/github-pages.html.

Mac/ Linux

touch .nojekyll

Windows

copy NUL .nojekyll

We render the website,

quarto render

then we push to the online repository.

git add .
git commit -m "Push website"
git push

Setup GitHub to “read” the website from the sub-folder docs.

You can publish your website (or book, as we will see in the next section) on a custom domain. For this you’d need to pay a monthly or yearly fee.

See for details this ultra-brief guide https://adrianstanciu.eu/sitedummy.html I wrote some time ago but still remains valid.

Book

For when you have particular expertise in a domain that you’d want to share publicly and freely.

Book

Why an online book

It can be shared online.

It can be easily structured into sections and chapters.

It can integrate r (as well as other languages) code.

You maintain full control over content and formatting.

It can be downloaded as PDF or EPUB (for e-readers, not covered in this class).

From it, one can download material…

Create quarto book project

Default quarto book

.qmd, .yml, .bib as well as a folder “_book”.

Render

A quarto book, like a quarto website, must be rendered first. This creates .html files inside the “_book” subfolder.

The index.html indexes the book. Brings everything together.

Live preview by typing in the Terminal:

quarto preview

Render by typing in the Terminal:

quarto render

The files

Identical with the .qmd for websites.

Identical with the one for creating websites but contains different attributes.

Output directory

We can specify the output directory where quarto should render the book files.

output-dir: docs

List all the chapters!

Remember to list under chapters: all the .qmd chapters you’d want to render to the final book. Otherwise these are not included. Note also that the order of chapters is defined here.

PDF of your book

You may inspect the PDF version of your book by navigating inside the “_book” (or “docs”, depending on the output-directory indicated in the .yml file) folder provided, of course, that you first rendered the book using, for example, the code line quarto render.

For nice(r) PDF book formatting, turn to latex formatting which can be integrated in the .yml file or yaml header.

Citation file format that gets integrated in the output document through pandoc.

.bib citation

Many journals offer the possibility to download a .bib citation of their articles.

For, example Conner & Armitage (1998)

Transform into .bib

One can use online tools for transforming plain text citations into .bib citation format. For example, https://asouqi.github.io/bibtex-converter/.

Create book content

Use the knowledge from previous sessions and create content for your book. Or, a basic structure that you could edit at a later stage.

Book content

Use data

Use data Stanciu et al. (2017) to integrate graphs and tables.

Use the Excel sheet movies.xlsx to integrate external source material.

Add chapters

Create multiple chapters that define a structure to the information you’d want to communicate.

For example: Preface, Reasoning, Data visualization, Discussion, Acknowledgment, About author.

Deploy book

First, quarto preview the book locally and make sure all is good.

Deploy book

We can deploy directly from Terminal to quartopub.com using

quarto render

then

quarto publish quarto-pub

GitHub publication

To publish the book via GitHub, follow the steps in the book R beyond data analysis.

https://adrian-stanciu.quarto.pub/r-beyond-data-analysis/.

General tips

Know what to look for

When in an impasse, know what to look for online:

Issues with data manipulation or analysis - check for r code/ packages.

Editing an .qmd or .Rmd – search for how to…in quarto/ Rmarkdown.

Formatting for HTML, search for .css or attributes of the .yml file or yaml header.

Render to PDF? Check for latex integration in the .yml file or yaml header.

Problem with citations? Check for .bib bibliography integration in quarto/ Rmarkdown.

Publish assignment via quartopub.com

All quarto documents can be published at quarto.com.

Reference list

Conner, M., & Armitage, C. J. (1998). Extending the theory of planned behavior: A review and avenues for further research. Journal of Applied Social Psychology, 28(15), 1429–1464. https://doi.org/10.1111/j.1559-1816.1998.tb01685.x
Stanciu, A., Cohrs, C. J., Hanke, K., & Gavreliuc, A. (2017). Within-culture variation in the content of stereotypes: Application and development of the stereotype content model in an eastern european culture. The Journal of Social Psychology, 157(5), 611–628. https://doi.org/10.1080/00224545.2016.1262812