Chapter 4 — Practice Demo Lab: Reference Solution

Lab: Set up a working R project together

Note

Reference solution for the Chapter 4 Practice Demo Lab (Tasks 1–7 of Lab: Set up a working R project together). The graded Canvas lab has its own private answer key.

Tasks 1–4 — Setup (expected outcome)

These are setup steps; the “answer” is a working project:

  1. Posit Cloud account — each member signs in at posit.cloud.
  2. Create the project — a project named frst232 with data/, outputs/, and R/ sub-folders.
  3. Install packagesinstall.packages(c("tidyverse", "readxl", "here")) completes without error (a package is a bundle of reusable functions; there are many because each solves a focused task).
  4. Upload the databc_disturbance_reforestation.xlsx sits in data/. Confirm with list.files(here("data")) — the file name should appear.

Task 5 — First import (everyone gets the same dim)

bc <- read_excel(here("data", "bc_disturbance_reforestation.xlsx"),
                 sheet = "Data")
dim(bc)          # expected: 37 8
[1] 37  8
names(bc)
[1] "Fiscal_Year"                   "Clearcutting_ha"              
[3] "Clearcutting_with_reserves_ha" "Partial_cutting_ha"           
[5] "Harvested_ha"                  "Natural_Disturbance_ha"       
[7] "Total_Disturbance_ha"          "Reforestation_ha"             

Every group member should see dim(bc) = 37 8 — 37 fiscal years, 8 columns. If someone sees something different, the usual cause is the file in the wrong folder or the wrong sheet=.

Task 6 — Compute and compare with Chapter 1

total_reforested <- sum(bc$Reforestation_ha)
total_reforested
[1] 8264064

sum(bc$Reforestation_ha) = 8,264,064 ha. Everyone in the group should get this same number, and it should match the =SUM(H2:H38) total from the Chapter 1 Excel workbook — the whole point of the Excel→R transition: same data, same answer, now reproducible.

Task 7 — Submit

Submit one screenshot showing a member’s RStudio/Posit Cloud with the BC file loaded, the column names visible, and the sum() result — with all group members’ names. (Graded lab: follow Canvas.)