Pre-Term Preparation

During Michaelmas term, you will learn how to work with Git, a tool used for collaboration, versioning and project management in scientific research. You will need a GitHub account to take part in learning and assessment, and should have received an invitation from “ms609” at GitHub asking you to join the @geol-skills organization.

We will be working with data in R, which has a lot in common with Python, but is better suited to certain statistical tasks. You’ll get to know R during the term, but it’ll help if you are familiar with the basics, so we don’t lose class time to fundamentals that you can work through at your own speed.

Before the first session, you will need to be able to complete some of the tasks you are already familiar with in Python using the R syntax. This will allow us to use our classroom time to focus on the interesting stuff: how to design and evaluate scientific research.

Time needed: Allocate yourself 3–4 hours total, spread over a few days so the new concepts have time to sink in, and you are confident with them ahead of the first session.


1. Set up Git (30 min)

You’ll use Git throughout this course to save your work, collaborate with your group, and build an audit trail for your report.

    • If you wish to use an existing GitHub account, add your Durham e-mail address as a secondary e-mail.
    • Your Durham affiliation gives you access to GitHub Pro and other benefits.
    • No e-mail yet? Check your junk mail folder. If there’s nothing there, e-mail Martin Smith, the module coordinator (firstname.lastname at durham.ac.uk), from your Durham e-mail account.

Optionally, once you’re done, you may wish to get to know GitHub by completing complete GitHub’s Introductory tutorial.


2. Learn the basics of R (2–3 hours)

Your Python training stands you in good stead: you don’t need to learn programming from scratch. But you will need to learn how R approaches tasks that you already know how to do in python.

What you need to be able to do by Week 1

These are the skills the Week 1 exercises assume. Check yourself against each one:

  • df <- read.csv("my_data.csv")
  • head(df)       # first 6 rows
    names(df)      # column names
    nrow(df)       # number of rows
    str(df)        # structure (types of each column)
  • df$temperature
  • mean(df$temperature)
    sd(df$temperature)
    min(df$temperature)
    max(df$temperature)
    summary(df$temperature)
  • plot(df$year, df$temperature,
         xlab = "Year", ylab = "Temperature (°C)")
  • hist(df$temperature, breaks = 20)
  • result <- 42
    greeting <- "hello"
  • celsius_to_kelvin <- function(temp) {
      temp + 273.15
    }

3. Quick self-test

Open the R console (either at webr.r-wasm.org in your browser, or in Positron if you’ve installed it) and try this:

# Create a small data frame
weather <- data.frame(
  month = c("Jan", "Feb", "Mar", "Apr", "May"),
  temp_c = c(3.2, 3.8, 5.9, 8.1, 11.2),
  rain_mm = c(52, 40, 44, 47, 50)
)

# Inspect it
head(weather)
names(weather)

# Summary stats
mean(weather$temp_c)
max(weather$rain_mm)

# Plot
plot(weather$temp_c, weather$rain_mm,
     xlab = "Temperature (°C)",
     ylab = "Rainfall (mm)",
     main = "Durham weather")

Read each line before you run it. Do you understand what the line is doing? Can you anticipate its output? If so, you’re ready for Week 1.


Troubleshooting

“I can’t install R / Positron” — You don’t need to for the first few weeks. All exercises run in the browser via WebR. If you want a local install, install R first, then download Positron. Positron is built on VS Code, so it will feel familiar if you used VS Code or Jupyter in GEOL1151; it runs Python too.

“I’m confused by <-” — Think of it as a left-pointing arrow: the value on the right gets stored in the name on the left. It’s R’s version of Python’s =.

“I’ve forgotten all my Python” — That’s fine. The programming concepts (variables, functions, loops, conditionals) are the same in every language. You’re learning new syntax for ideas you already understand.