[1] "/Users/czmann/Documents/teaching/stat331/stat331-calpoly-s25/slides/week-1"
Today we will…
In computing: analyses can be executed again with identical results (either by you or by someone else!)
Discussion: Why does it matter?
Abstruse Goose
You can to send your code to someone else, and they can jump in and start working right away.
This means:
You can to send your code to someone else, and they can jump in and start working right away.
This means:
[1] "/Users/czmann/Documents/teaching/stat331/stat331-calpoly-s25/slides/week-1"
This file lives in my user files Users/
…
…on my account czmann/
…
…in my Documents
folder …
…in a series of organized folders.
absolute file path: full path from the root directory on your computer
relative file path: path based on the relationship with a current working directory in terms of a hierarchichy of directories
../
is the relative path to a parent directoryWarning
An absolute file path will only work on your computer!!
[1] "/Users/czmann/Documents/teaching/stat331/stat331-calpoly-s25/slides/week-1"
R
“thinks it lives” in at the moment.
Warning
If you are in practice of using setwd()
to set a working directory in R
FORGET THIS. We will be using other, better practice methods to set a working directory.
Relative file paths allow someone else to run your code exactly (reproducibly!), as long as they
have everything organized the exact way that you do and
the same working directory
Enter R Projects!
Opens RStudio
Sets the working directory to be wherever the .Rproj file lives.
Has any files open or elements in your environment that you last saved.
Links to GitHub, if set up (more on that later!)
R Projects are great for reproducibility!
R Projects are great for organization
File > New File > R Script
) are files of code that are meant to be run on their own.Scripts can be run in RStudio by clicking the Run
button at the top of the editor window when the script is open.
You can also run code interactively in a script by:
highlighting lines of code and hitting run.
placing your cursor on a line of code and hitting run.
placing your cursor on a line of code and hitting ctrl + enter
or command + enter
.
Notebooks are an implementation of literate programming.
They allow you to integrate code, output, text, images, etc. into a single document.
E.g.,
Reproducibility!
Markdown is a markup language.
It uses special symbols and formatting to make pretty documents.
Markdown files have the .md extension.
Quarto uses regular Markdown, AND it can run and display R
code.
To take your .qmd file and make it look pretty, you have to render it.
When you render:
Quarto CLI (command line interface) orchestrates each step of rendering:
knitr
or jupyter
.R code chunk options are included at the top of each code chunk, prefaced with a #| (hashpipe).
Anything other that code and output should be included as Markdown in a Quarto notebook
Some Markdown text basics:
Find more Markdown basics here.
#’s are used in three different ways in Quarto documents…
Use relative file paths!
Remember that when you run code within a .qmd file or render it, the working directory is the directory where the .qmd file is saved.
Quarto makes moving between outputs straightforward.
Supports reproducibility!
Consistent implementation of pretty and handy features across different formats
Guardrails that are helpful when learning:
Support for other languages like Python, Julia, Observable, and more.
Artwork by Allison Horst