6  Getting Started with R in Posit Cloud

NoteWhat you’ll be able to do

By the end of this chapter you will be able to:

  1. Set up Posit Cloud and create a project.
  2. Work from a saved, commented script rather than the console.
  3. Distinguish installing a package (once) from loading it (every session).
  4. Import a dataset and check what came in with str() and summary().
  5. Apply the course’s number-reporting conventions.

Before you can run any analysis in this book, you need two pieces of software:

You can use R without RStudio, but you almost certainly don’t want to. RStudio gives you a script editor, a console, a data viewer, and an environment panel in one window. Every example in this book assumes you’re working in RStudio.

This course uses Posit Cloud: the same RStudio interface, running in your web browser, with nothing to install. You can be working in two minutes, on any machine — including a locked-down lab computer or a Chromebook.

If you ever want R on your own computer, both R and RStudio are free downloads from cran.r-project.org and posit.co — everything in this book works identically. Ask if you want help setting it up.

6.1 Setting up Posit Cloud

  1. Go to https://posit.cloud/plans.
  2. Choose the Cloud Free tier and create an account.
  3. Click New Project → New RStudio Project. This is your course project: you’ll use this one project all semester.

You’ll get the RStudio layout (described below), running on a server. Save your work regularly.

The free plan gives you a monthly allowance of compute hours, and the clock runs whenever a project is open. A project you stop using is suspended after 15 minutes of inactivity; logging out does not stop the clock sooner. If you use up the month’s hours, you can’t open projects until the next month starts. posit.cloud/plans/free lists the current allowance. Close the browser tab when you’re done, and don’t leave a project open overnight.

6.2 The four panes

When your project opens, you’ll see three panels (called panes), with the Console filling the left side. Once you open a script, the left side splits and you have four:

Pane Where What it’s for
Console Bottom-left The live R prompt. Type commands here for immediate results.
Script Editor Top-left (after you open one) Where you write and save R scripts.
Environment / History Top-right Lists every variable, dataset, and function currently in memory.
Files / Plots / Packages / Help Bottom-right File browser, plot output, package management, and R’s built-in help.

You can resize the panes by dragging their borders. The default layout is fine for most work.

6.3 Work in scripts, not the console

Real analysis lives in scripts, not the console. The console is for trying things out; the script is the record you save.

  1. Go to File → New File → R Script.
  2. Type a comment at the top — every R script should start with a brief description:
# Statistics 224 — homework 1
# Jane Doe, 2026-09-10
# This script analyzes the Babies dataset for normality.
  1. Save it (Ctrl/Cmd-S). Use a descriptive filename — homework1.R, not Untitled1.R.

6.4 Getting data into R

In this course, data reaches you in one of three ways. You’ll use the first one almost every time.

Every course dataset lives at the same web address. Only the file name at the end (here, ch14_lattes.csv) changes:

data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch14_lattes.csv")
str(data)
'data.frame':   20 obs. of  2 variables:
 $ cup        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ caffeine_mg: int  181 198 130 156 155 169 135 210 163 193 ...

Copy the line from the assignment rather than retyping it. The address needs quotation marks around it. If you see cannot open the connection, the address has a typo: check the file name first.

Try it now: run the two lines above. Your Environment pane should list data with 20 obs. of 2 variables.

Some datasets come inside an R package, so there’s no file or URL:

library(UsingR)
data(babies)

You’ll use this one in Chapter 7.

For data of your own, such as a final project: in the bottom-right pane, click the Files tab, then Upload, and choose your file. Then read it in by name:

data <- read.csv("my_data.csv")              # CSV file
data <- readxl::read_excel("my_data.xlsx")   # Excel file (readxl comes with the tidyverse)

6.5 A clean workflow

Here is the routine for starting a new analysis. Adopt it from day one and you’ll save yourself headaches later.

  1. Open your course project. A project bundles your scripts, data, and output in one folder so paths don’t break. Don’t start a new project for each assignment: packages install per project, so every new project means reinstalling them all (a few minutes each time).
  2. Open a new R script. File → New File → R Script.
  3. Save the script with a clear name before you write any code.
  4. Load the data. Usually that’s the read.csv() line from the assignment (see the tabs above).
  5. Inspect what came in. Always run str(data) and summary(data) immediately. Don’t skip this — it’s how you catch wrong column types and missing values before they cause trouble.
  6. Analyze. From here, you’re in the territory of Parts III–V of this book.
  7. Save. Save the script frequently. Save plots with ggsave() or by clicking Export in the Plots pane.
TipReporting numbers in this course

Some conventions you will need from the very first homework onward:

  • Report all numbers to two decimal places except for p-values and whole-number counts. Counts such as N, n, and ordinary degrees of freedom stay whole: N = 40, not 40.00. (Welch’s fractional df gets two decimals, like any other number.)
  • Report p-values to three decimal places.
  • If a p-value is very small (e.g., \(9.78 \times 10^{-9}\)), report it as \(p < .001\) rather than copying the scientific notation.
  • No leading zero on numbers that can’t exceed 1, such as p and r: write p = .024, not 0.024.
  • Always write t, F, p, and r in italics in your write-up (χ² stays upright: Greek letters are not italicized).

These conventions come from APA style and apply throughout the rest of the book; Chapter 26 has the full set.

6.6 Installing packages

R’s base functionality is augmented by packages — bundles of code written by other people. You’ll install several over the course of the semester. The pattern is:

# Install once (downloads the package into your project)
install.packages("ggplot2")

# Load once per R session (makes the package's functions available)
library(ggplot2)

You do not need to re-run install.packages() every session. You do need to re-run library() every session, because R starts each session with only base packages loaded.

Packages you will need over the course of the semester:

Package What it’s for Chapter
ggplot2 Plotting (grammar of graphics) Chapter 8
tidyverse A bundle including ggplot2, dplyr, tidyr, and others several
UsingR The Baby Dataset (and other teaching datasets) Chapter 7
palmerpenguins Example dataset for plotting Chapter 8
reshape2 The Tips dataset; reshaping Part VII
e1071 Skewness and kurtosis Part III
nortest Additional normality tests (Anderson–Darling) Part III
car Diagnostic plots, VIF, and assumption checks Parts IV–V
vcd Cramér’s V (assocstats()) Chapter 21
afex ANOVA, especially repeated-measures and mixed designs Part IV
emmeans Post-hoc comparisons after ANOVA Parts IV–V
effsize Cohen’s d Parts III–IV
effectsize eta-squared, Cramér’s V, Cohen’s w Parts IV and VI
rstatix Effect sizes for non-parametric tests Parts III and VI
pwr Sample size and power analysis Appendix E
coin Backend rstatix needs for Wilcoxon effect sizes Part III
sandwich Robust (heteroscedasticity-consistent) standard errors Chapter 25
lmtest coeftest(), which reports a model with robust standard errors Chapter 25

A single command installs all of them at once:

install.packages(c("tidyverse", "UsingR", "palmerpenguins", "reshape2",
                   "e1071", "nortest", "car", "vcd",
                   "afex", "emmeans", "effsize", "effectsize", "rstatix", "pwr",
                   "coin", "sandwich", "lmtest"))

This may take a few minutes the first time. Each package, and the packages it depends on, has to download and install. In Posit Cloud, packages install per project — a new project starts fresh, which is why the course uses one project all semester. If you ever do start a new project, re-run this install command once in it.

6.7 Troubleshooting

A handful of issues come up nearly every semester. Here are the fixes.

could not find function "..." — Either you forgot to load the package (run library(packagename)), or the function name has a typo. R is case-sensitive: t.test() works, T.test() doesn’t.

“There is no package called ‘X’” — The package isn’t installed. Run install.packages("X").

object of type 'closure' is not subsettable — Your dataset isn’t in memory. The name data also belongs to a built-in R function, so when your dataset is missing, R finds that function instead and complains that it can’t pull a column out of a function. (str(data) or head(data) will print a block of R code instead of your variables — same cause.) Run your import line again. With any other name, such as babies, the same mistake gives the plainer object 'babies' not found: check that the name you’re using matches the one on the left of <-.

Not sure what a function does or what it needs? Run ?functionname — for example, ?t.test — and its help page opens in the Help pane, with the arguments it takes and examples at the bottom.

RStudio looks frozen — A long computation may be running. Check the red stop sign at the top of the Console pane; if it’s visible, R is busy. You can usually click it to interrupt.

If something stranger goes wrong, the Console error message is the first thing to read — it almost always names the problem. Copy and paste that into a web search before asking; most R errors have been seen and answered many thousands of times before.

The next chapter takes you through the standard data-preparation steps you’ll repeat at the start of every analysis.


TipChapter Summary

Core idea: R is the computational layer for this course, and Posit Cloud is where you run it. You install packages once per project; you load them every session. RStudio is the environment that makes R usable.

You should understand:

  • The difference between the R console (run code immediately) and a script (save and re-run)
  • Why install.packages() runs once but library() runs every session
  • How to find help for any function: ?functionname

You should be able to do in R:

  • Install a package: install.packages("ggplot2")
  • Load a package: library(ggplot2)
  • Install several at once: install.packages(c("tidyverse", "car", "effsize"))

Plain-language check: A classmate says “I installed ggplot2 last week but now R says it can’t find the function.” What is likely wrong, and how do you fix it?

The one mistake to avoid: Forgetting library(). Installing a package puts it in your project; it doesn’t load it. Put a library() line for every package at the top of each script, and run it every session. (Leave install.packages() out of scripts you share: install once, load every time.)

Practice: Open Posit Cloud, install the effsize package, load it, and confirm it loaded by running ?cohen.d. What does that function do?

Key terms from this chapter are defined in the Glossary.