EE BIOL C177/C234
here| What it is | What you see | What you do with it | |
|---|---|---|---|
| R Project | The “home” folder of one analysis | eeb_c234.Rproj |
Double-click to open your work. No code in it! |
| R script | A text file of R code | 07_workspace.R |
Write code, save, run line by line |
| Console | Where R runs code right now | The > prompt |
Quick tests. Nothing is saved. |
🧪 Project = your lab bench · Script = your written protocol · Console = scratch paper
📝 Script: anything needed to reproduce a result
library(tidyverse)🗒️ Console: one-time or throwaway
pak::pak("palmerpenguins") (install once per computer)?filter (help pages)glimpse(penguins) (a quick peek)If you closed RStudio right now, could you redo your analysis? Only if it’s in the script.
eeb_c234 (no spaces), inside e.g. Documents
Downloads, not inside another projectdata, then figuresUsing Positron?
No .Rproj needed: File > Open Folder… and pick the project folder.
eeb_c234/ <- the project folder
├── eeb_c234.Rproj <- double-click this to open the project
├── 07_workspace.R <- your script for this chapter
├── data/ <- raw data files go here
└── figures/ <- saved plots go hereOne project for the whole course. For research: one project per paper or analysis.
.Rproj FileDouble-click eeb_c234.Rproj every time
(or File > Open Project…, or the project menu in the top-right corner)
.R file opens RStudio without the project → R looks for files in the wrong folderCtrl/Cmd + Shift + N)Ctrl/Cmd + S) as 07_workspace.R in the project folder* = unsaved changes. Save often!File names: no spaces, lowercase, numbered so they sort in order
✅ 07_workspace.R ❌ My Script FINAL (2).R
# = comment: R ignores it; it’s a note to future you# Name ---- = section: jump around with the outline (Ctrl/Cmd + Shift + O)| Action | Windows / Linux | Mac |
|---|---|---|
| Run current line / selection | Ctrl + Enter |
Cmd + Return |
| Run the whole script | Ctrl + Shift + Enter |
Cmd + Shift + Return |
| Save | Ctrl + S |
Cmd + S |
| Restart R | Ctrl + Shift + F10 |
Cmd + Shift + 0 |
+ in the Console = R is waiting for you to finish (missing ), ", or a trailing |>). Press EscWorking directory = where R looks for files. With the project open, it’s the project folder.
setwd() in a script: open the project instead/, even on Windows ("data\x.csv" is an error)Data/ ≠ data/list.files("data") shows what R can seehere Package
here::here(): Paths from the Project Root.Rproj file.R script and in a .qmd in a subfolderOnce: Tools > Global Options… > General
Every time before you share or submit:
Ctrl + Shift + F10 / Cmd + Shift + 0)Ctrl/Cmd + Shift + Enter)No errors? Then anyone with your project folder can reproduce your results.
Your script, not your R session, is the record of your work.
| What you see | Likely cause | Fix |
|---|---|---|
'data/x.csv' does not exist in current working directory |
Project not open, file not in data/, or a typo |
Check the top-right corner; getwd(); list.files("data") |
could not find function "ggplot" |
Package not loaded (restarting R unloads everything) | Run the library() lines at the top |
object 'my_data' not found |
That line wasn’t run this session, or was only typed in the Console | Run the script from the top |
Console shows + and nothing happens |
Missing ) or ", or a trailing |> |
Esc, fix, run again |
| Edited the script, output didn’t change | Saving is not running | Run the line again |
| Your files aren’t in the Files pane | RStudio opened from its icon or a .R file |
Open eeb_c234.Rproj |
eeb_c234data and figures.RData saving/restoring07_workspace.R → add a header, the library() lines, and a first plotgetwd() in the Consoleeeb_c234.Rproj✅ Top-right shows eeb_c234 · getwd() ends in eeb_c234 · packages load without errors (“Attaching packages” / “Conflicts” messages are normal)
From now on: every chapter gets its own script in this project (08_dplyr.R next).
Your Workspace