[1] 327216
[1] "Imagine Dragons"
R Onboarding
Vienna University of Economics and Business (WU)
November 2026
Self-paced, about 2–3 hours, before session 2. These slides summarize the onboarding module in the course book — the book has all details, screenshots, and the complete R code.
AI writes R code cheaply — that does not make R skills obsolete, it shifts them: the scarce skill is no longer typing code, but reading and checking it.
Route A (recommended): local installation
Install in this order, with the default settings. RStudio is built on top of R: R without RStudio works — RStudio without R does not.
Route B (fallback): Posit Cloud
RStudio in the browser — no installation: https://posit.cloud → New Project → New RStudio Project.
Useful if the installation fails or your computer is managed by an employer. Free accounts have usage limits.
C:/marketing-analyticsxcrun → run xcode-select --install in the Terminal appmacOS: “Operation not permitted” when knitting or reading files → RStudio lacks permission to access the folder.
System Settings → Privacy & Security → Files & Folders (or Full Disk Access): allow RStudio, then restart RStudio — or keep the course folder directly in your home folder (~/marketing-analytics).
| Pane | Purpose |
|---|---|
| Script editor | Write and keep your code (.R file) |
| Console | R executes code and prints results |
| Environment | Objects in your current session |
| Files / Plots / Help | Files, charts, help pages |
Always write code in a script. Run a line with Ctrl + Enter (Mac: Cmd + Enter).
File → New Project → New Directory → New Project
.Rproj file)setwd("C:/Users/…"): hard-coded paths break on every other computerChange one setting now: Tools → Global Options → General
Your script is the record of your work — not the workspace.
marketing-analytics/ <- project folder
├── marketing-analytics.Rproj
├── code/ <- .R and .Rmd files
├── data/ <- .csv, .xlsx, .sav
└── graphics/ <- saved charts
Refer to files by their relative path:
read_csv2("data/music_data_fin.csv")ggsave("graphics/genre_shares.png")Never edit raw data by hand · no spaces or brackets in file names: assignment-1.Rmd, not Assignment 1 (final).Rmd
code/first-steps.RThe console shows + instead of >? R is waiting for you to finish a command — usually a missing closing bracket or quotation mark. Complete the command, or press Esc to abort.
[1] 327216
[1] "Imagine Dragons"
<- assigns (shortcut Alt + -, Mac: Option + -) · # starts a comment · R is case-sensitive: streams ≠ Streams · names: lower case with underscores, e.g., mean_streams
[1] 1 4 7 10
[1] 1 4 7 10
[1] 3.14
Named arguments can come in any order · help for any function: ?seq or F1 on the function name · Tab shows completions while you type
| Type | Example |
|---|---|
| numeric | 163608, 3.14 |
| character | "Dance" |
| factor | factor(c("Pop", "Rock")) |
| logical | TRUE, FALSE |
| Date | as.Date("2026-10-12") |
Convert with as.numeric(), as.character(), as.factor(), as.Date()
[1] 163608 126687 120480
'data.frame': 3 obs. of 2 variables:
$ artist : chr "Ed Sheeran" "Imagine Dragons" "J. Balvin"
$ streams: num 163608 126687 120480
install = once per computer · library = every session
could not find function "…"? → the package is probably not loaded. Without loading: dplyr::filter()
“Keep the pop tracks and compute their average number of streams”:
| Dialect | Strength | Drawback |
|---|---|---|
| Base R | always available | hard to read |
| tidyverse | reads like a sentence; ggplot2 |
needs packages |
| data.table | very fast | cryptic for beginners |
This course uses the tidyverse: readable pipelines are easy to check — whether you or an AI wrote them. Be able to read base R.
| Action | Windows | Mac |
|---|---|---|
| Run line / selection | Ctrl + Enter | Cmd + Enter |
| Run whole script | Ctrl + Shift + Enter | Cmd + Shift + Enter |
Assignment <- |
Alt + - | Option + - |
| Pipe |> | Ctrl + Shift + M | Cmd + Shift + M |
| Insert code chunk | Ctrl + Alt + I | Cmd + Option + I |
| Knit | Ctrl + Shift + K | Cmd + Shift + K |
| Comment lines | Ctrl + Shift + C | Cmd + Shift + C |
Native pipe: Tools → Global Options → Code → Editing → tick “Use native pipe operator, |>” — otherwise the shortcut inserts %>%.
Own shortcuts: Tools → Modify Keyboard Shortcuts…
Why read_csv2() and not read_csv()? → first lesson of Chapter 2.
File → New File → R Markdown… → HTML → save as code/first-report.Rmd → Knit
Three ingredients:
---: title, author, output**bold**, *italic*, # Heading```{r} and ````r nrow(music_data)` puts results into the textThe golden rule: a report knits in a fresh R session. Everything it needs — library(), loading the data, every step — must be in the report. Works in the console but not when knitting? You rely on something that exists only in your session.
Keep the chunk delimiters intact: every chunk needs three backticks at the start (```{r}) and at the end (```). One deleted backtick → the report no longer knits. Insert chunks with the shortcut.
File paths in reports: a report in code/ finds the data at "../data/music_data_fin.csv" (.. = one folder up).
| Message | What it usually means |
|---|---|
could not find function "…" |
Package not loaded — or function name misspelled |
object '…' not found |
Typo, wrong capitalization, or the creating line was not run |
cannot open file '…' |
Wrong place or wrong name — are you in your RStudio Project? |
unexpected symbol / unexpected ')' |
Missing comma, bracket, or quotation mark |
there is no package called '…' |
Not installed yet → install.packages("…") |
Errors are not a sign that you are doing something wrong — they are R’s way of telling you where to look. Read the message first.
Chat assistants — ChatGPT, Claude, Gemini, Perplexity
Inside RStudio — GitHub Copilot suggests code as you type: Tools → Global Options → Copilot (GitHub account; free for verified students via GitHub Education)
Good at: standard code (wrangling, charts, loops) · explaining functions and errors · debugging · suggesting alternatives
Less reliable at: statistical reasoning and interpreting results — fluent even when wrong
I am working in R with the following data frame:
> str(music_data)
'data.frame': 66796 obs. of 31 variables:
$ isrc : chr "BRRGE1603547" ...
$ danceability: num 50.9 35.3 68.3 ...
$ valence : num 65.1 43.7 43.4 ...
Please provide the code for a publication-ready
scatterplot between valence and danceability with
pink hollow circles and a red regression line, and
label the line with the regression coefficient.
str() output, code, the complete error messageDebugging works too: could not find function "geom_pont" + your code → the assistant spots the typo (geom_point()) and returns the corrected code.
An assistant explained R’s percentile calculation correctly — and then reported the median of 1, 2, 10 as 2.5. Five seconds in R:
What saved the day was not a better prompt, but running the code and checking the result.
code, data, graphicsdata/str(music_data)HTML opens and shows the structure of the data? Your setup works.
Stuck? Forum on Canvas, your AI assistant — and the setup clinic at the start of session 2.
Marketing Analytics — Nils Wlömert