Requirements for Scripts You Write in this lab

The following requirements are MANDATORY for all lab assignments and should be considered best practices for all future R scripts in this course. Adherence to these standards is crucial for proper evaluation of your work and development of good coding habits.

Script Header

Every script MUST begin with a header containing the following information:

###########################
# Lab Assignment: [Assignment Name]
# Author: [Your Full Name]
# Date: [Current Date]
# Course: MES503
###########################

Library and Data Import

Immediately following the header, set your working directory, and load ALL required libraries and import necessary data:

# Setting Working Directory
setwd("YOUR_WORKING_DIRECTORY")

# Load required libraries
library(tidyverse)
library(ggplot2)
# Add any other necessary libraries (you can come back and add these later)

# Import data
data <- read.csv("your_data_file.csv")
# Include any other data imports here

Question and Answer Format

All underlined statements and questions must be answered and addressed in your scripts using commented text and with corresponding numbers (e.g., #1. ANSWER HERE) Put these answers in same locations and order as presented in the homework. You may also copy the question text if you wish, but this is not required.

Example:

If the activity contains something like the following:

  1. What is the average fish length?

you must answer in your script like so

avg_length <- mean(data$length, na.rm = TRUE)
# 1. The average fish length is [insert value] units.

Code Organization

  • Organize your code into logical sections - with reasonable indentations. I dont require any specific formatting, just make it so that you can follow what you did and that it tracks with the homework.

  • Use meaningful variable names that clearly indicate the content or purpose.

  • never overwrite original data or important variables.

    Tip

    the first activity you are about to do has a well formatted template. consider maintaining this format and indentation for all your activitieis and assignments.

Data Visualization

When creating plots, include all the required plot components.

Example:

library(ggplot2)

# example data
length = rnorm(50, 30, 10)
dat <- data.frame(
  length= length,
  weight = length * rnorm(50, 5, 1)^3)

# Create a scatter plot of fish length vs. weight
ggplot(dat, aes(x = length, y = weight)) +
  geom_point() +
  labs(caption = "Figure 1: relationship between fish length and weight at site X in year X",
       x = "Length (cm)",
       y = "Weight (g)") +
  theme_bw()

Remove Install.packages() Commands

Do not include any install.packages() commands in the scripts that you submit to me. It is bad practice to include this command because it risks changing the computer settings of the user (in this case ME).

Not allowed under any circumstances:

install.packages("tidyverse")

Alllowed, but not preferred (can be messy, a little redundant)

#install.packages("tidyverse")

Required

library(tidyverse) # or any library you need 

Final Checks

Before submission, clear your working directory and environment, restart R, and re-run the script entirely to ensure that your script is your source of truth. Verify the following:

  1. Your script runs without errors. I cannot grade a script that does not run. Errors will result in severe point deductions!

  2. Your heading is properly formatted.

  3. All required libraries are loaded.

  4. There are no install.packages() commands in the script.

  5. Data is imported correctly.

  6. All questions are answered completely and with appropriate formatting and location in the script.

  7. Code is organized and easy to follow, properly indented and formatted for readability.

  8. Plots are well-formatted and labeled.

  9. There are no extraneous code blocks (you are welcome to try things out, but add comments describing what you did if you do go on a tangent).

  10. The script is saved and submitted as a .R file.

Failure to comply with these requirements will result in point deductions. These standards are designed to foster good coding practices and ensure consistency across all student submissions.