###########################
# Lab Assignment: [Assignment Name]
# Author: [Your Full Name]
# Date: [Current Date]
# Course: MES503
###########################
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:
Library and Data Import
Immediately following the header, set your working directory, and load ALL required libraries and import necessary data:
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:
- 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.
Tipthe 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
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:
Your script runs without errors. I cannot grade a script that does not run. Errors will result in severe point deductions!
Your heading is properly formatted.
All required libraries are loaded.
There are no
install.packages()
commands in the script.Data is imported correctly.
All questions are answered completely and with appropriate formatting and location in the script.
Code is organized and easy to follow, properly indented and formatted for readability.
Plots are well-formatted and labeled.
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).
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.