Over the course of the first week of EDS 221, you’re going to implement the coral reef model in R. This project provides an opportunity to integrate foundational programming concepts: data structures, control structures, and functions. All of your work on this project will live in a single repository.
Today’s end-of-day practice lays the groundwork for the rest of the work you’ll do this week. By the end of this activity, you will have:
- Local and remote repositories to track your progress
- A README describing your project
- A script that rolls two dice
The following sections describe your goals and how to validate them. The instructions are deliberately left vague - use your notes and the activities from earlier today (e.g., live coding scripts) to guide you!
Version control tasks
- Initialize a local git repository for your project in your eds221/ folder.
- In your repository, create README.md. Add 2-3 sentences describing the coral reef model at a high level. This should be a summary, not step-by-step instructions.
- Commit your changes.
- Create a remote repository on GitHub.
- Push your local repo to the remote.
Validation checks
Check that…
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
Code execution tasks
- Create a script called roll_dice.R.
- Paste the following code in roll_dice.R.
set.seed(123)
die <- 1:6
rolls <- sample(die, size = 2, replace = TRUE)
roll_total <- sum(rolls)- Run the code in roll_dice.R at the console.
- Save your script, then commit and push your changes.
Validation checks
Check that…
Wrap up
Congrats - you’ve completed your tasks for day 1!
Today you learned:
How code executes
- Code is made up of expressions, where operators and functions act on variables and values to make things happen.
- Code has a flow from scripts to the console to the environment.
- Expressions build on each other to perform complex tasks using simpler parts.
How to track changes
- git records the history of your coding projects in repositories.
- git commands “move” files between the working directory, staging area, local repository, and remote repository.
- GitHub hosts your remote repositories, so you can share code and collaborate!
More information
What’s a .md file?
You may have noticed your README file ends in .md. That means it’s a Markdown file. Markdown is a lightweight language for formatting text. All the formatting is included directly in the text (as opposed to a Word document, for example), so it’s much more compatible with version control. You’ll learn more about Markdown next week. In the meantime, if you’d like to learn more, check out Markdown Tutorial and GitHub for Beginners: Getting started with Markdown.
Why is the value of roll_total 9?
Rolling dice is random, so how come everyone’s supposed to get the same value? What a great question! For now, I’m going to leave this to you to ponder. Have another look at the code I gave you and, if you’re so inclined, come up with a hypothesis for why every student should get the same random numbers. We’ll discuss this on Day 4.