ETF5922 Chap.3 R Foundations and Reproducible Projects
R Foundations and Reproducible Projects
Objects need declared origins
Atomic vectors store one basic type, and logical expressions can select or modify their elements. R uses NA for unavailable values, so summaries require an explicit missing-value policy.
Projects replace fragile paths
Factors encode categorical levels, while ordered factors permit ordinal comparisons.
Projects, relative paths and clean-session execution make an R analysis reproducible on another computer.
The clean-session test
A script that works only after earlier console actions depends on objects or packages it never creates.
Restarting R exposes that hidden dependency and shows exactly what the reproducible workflow must declare.
The clean-session test in context
R distinguishes object types, missing values and factor levels in ways that directly affect visual output. Character categories may sort differently after conversion to factors, numeric operations may propagate NA, and a reused object can hide an omitted transformation.
Project discipline makes these dependencies visible. Scripts should create objects from declared inputs, use stable relative locations and record package calls. A clean-session rerun is stronger than checking whether the final picture resembles an earlier one because it tests the entire chain. The resulting narrative should report both the computed value and the availability condition that shaped it.
What this chapter covers
- 01
Atomic vectors store one basic type, and logical expressions can select or modify their elements.
- 02
R uses NA for unavailable values, so summaries require an explicit missing-value policy.
- 03
Factors encode categorical levels, while ordered factors permit ordinal comparisons.
- 04
Projects, relative paths and clean-session execution make an R analysis reproducible on another computer.
- 05
Use vector and numeric to frame the reader's task
- 06
Check character against logical before styling
- 07
Explain how factor changes the visible comparison
- 08
Audit level without removing necessary context
Rebuild a summary from a clean session
- 1Count available observations and mark the unavailable entry as NA.
- 2Add only the observed values, then divide by the observed count.
- 2Report missingness separately from the mean so completeness is visible.
- 1Run the code from a clean project to confirm no interactive object supplies the result.
- 2Write the numeric conclusion with its missing-value condition.
Key terms
- Atomic vector
- A one-dimensional collection whose elements share a common underlying type in R.
- Missing value
- An explicitly unavailable observation represented by NA, not the number zero or an empty string.
- Factor level
- A categorical variable whose permitted categories and ordering influence summaries and plots.
- Project root
- The directory anchor that keeps scripts, data and outputs addressable without machine-specific paths.
R Foundations and Reproducible Projects FAQ
Why can a clean-session failure reveal hidden state?
A script that works only after earlier console actions depends on objects or packages it never creates. Restarting R exposes that hidden dependency and shows exactly what the reproducible workflow must declare.
What must a reproducible R project declare?
It should identify inputs, package dependencies, object creation order, missing-value treatment and project-relative locations for data and outputs. Running from a clean session is the practical test. If manual console work is required, the project has not yet captured the complete analytical state.
Why report completeness beside a mean?
A mean alone cannot reveal how many expected observations contributed. Reporting four observed values out of five distinguishes an estimate based on available data from a complete record and prevents NA from being silently reinterpreted as zero or ignored without explanation.
What evidence shows that a project is portable?
A second clean environment can open the project, restore dependencies, locate declared inputs and reproduce outputs without editing personal paths. Recording package requirements and keeping derived files separate from inputs make failures interpretable. Portability is demonstrated by reconstruction, not by copying a workspace image that contains hidden objects.
Exam move
Create a small project containing a script, a data file and one output. Include a factor and an NA value, restart R, and run the script without touching the console first. Record every failure as a missing dependency, path or object-creation step. Repeat until a second clean session produces the same summary and plot from the project alone.
Working through R Foundations and Reproducible Projects in ETF5922? Sia is AskSia’s AI Computer Science tutor — ask any ETF5922 R Foundations and Reproducible Projects question and get a clear, step-by-step explanation grounded in how ETF5922 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.