DATA 505: Lab 5
Function-oriented programming: from script to organized project
Solution
Overview
Your task: Refactor life_expectancy_script.R (an imperative script) into a well-organized function-oriented project with six functions.
What you’ll submit: A .zip file of your life_expectancy/ directory with working functions and pipeline.
Initial script
Download life_expectancy_script.R.
This script analyzes life-expectancy data from the gapminder package using regression models, in several steps.
Your Task
Step 1: Set Up Project
Download and unzip the R project life_expectancy_project.zip directory, then open the life_expectancy.Rproj file in RStudio. The project directory contains:
life_expectancy/
├── data/
│ └── new_countries.csv
├── R/
│ ├── 01_prepare_data.R
│ ├── 02_visualize.R
│ ├── 03_model.R
│ ├── 04_compare.R
│ └── 05_predict.R
├── output/
├── main.R
└── life_expectancy.Rproj
Step 2: Write the Six Functions
Complete each function file in R/ so that main.R runs to completion and produces all expected output. Use life_expectancy_script.R as reference while writing the functions.
Step 3: Submission
Submit .zip of the finished project directory (all six functions defined and main.R running as expected). You can use the R command zip("life_expectancy_YOURNAME.zip", here()) to do this. Submit the zip file on Moodle.