EDS 221 Day 4 AM

Function basics


August 13th, 2026

Information overload?


After three consecutive days of new content, it’s normal to feel overwhelmed.

Your hard work will pay off!


This is your training montage!

Take care of yourself


Learning needs down time. This weekend, take the time for rest and relaxation.

Successful students


Everyone here has what it takes to succeed in this class and in this degree!

The pace can be overwhelming, but you’ll get what you need from this course when you:

  • Show up and participate
  • Ask for feedback from peers and instructors
  • Take breaks to digest new knowledge

Day 3 exit tickets


Muddiest points

A lot of what we are doing with respect to the reef model has not been intuitive to me and I’d really like to develop that intuition.

Not being handheld when it comes to writing code. Simply starting based on verbal instructions is very difficult for me. But we persevere.

Coding it LOL… I understand it conceptually and on paper better.

How do we develop intuition?

Day 3 exit tickets


What I can do as your instructor

  • More explanation during live coding
  • Go over worksheets together in class

Day 3 exit tickets


What you can do as a student

What’s worked for you?

Review day 3


On a sheet of paper, draw a table with 4 rows and 2 columns. Label the columns big_fish and mass.

Trace the loop to right in your table. Each row represents one iteration of the loop and each column represents a variable.

Write down the value each variable will have at end of each loop iteration.

fish_mass_kg <- c(0.2, 1.9, 
                  0.03, 3.0)
big_fish <- 0
for (mass in fish_mass_kg) {
  if (mass >= 1) {
    big_fish <- big_fish + 1
  }
}

Function definitions


Function definitions have four main parts

The function keyword tells R this is a function definition.

The parameters inside the parentheses declare the function’s inputs.

The body of the function is enclosed in the curly brackets.

The return value comes at the end of the body and defines the function’s output.

roll_die <- function(n_sides = 6) {
  roll <- sample(1:n_sides, 1)
  return(roll)
}

Function calls


Function calls invoke function definitions

The arguments inside the parentheses feed into the parameters.

Arguments match parameters by position or by name.

Without an argument, parameters may take on a default value.

roll_die <- function(n_sides = 6) {
  roll <- sample(1:n_sides, 1)
  return(roll)
}

roll_die(6)

roll_die(n_sides = 6)

roll_die()