Objects Are The Unit of Reasoning
bookOne :: chapter-2Objects Are The Unit of Reasoning
R does not reward speed. It rewards correct mental models.
Most frustration with R comes from importing habits from other languages: step-by-step execution, mutable variables, hidden state. R rejects this worldview quietly, then punishes you later.
The alternative worldview is simple but demanding:
In R, thinking happens in objects.
Objects Exist Independently of Action
Consider the first meaningful act in R:
Kesulitan dengan riset atau tugas akademik Anda?
Tim ahli Notivra siap mendampingi Anda memberikan solusi bimbingan dan dukungan akademik yang komprehensif.
x <- c(3, 6, 9)
This line does not do anything in the procedural sense.
No computation is performed. No analysis begins.
An object comes into existence.
From R’s perspective, the most important questions are not:
- What are the values?
but: - What is this thing?
- What structure does it impose?
- What operations make sense now?
That is why the first tools of a serious analyst are not modeling functions, but inspection:
typeof(x)
length(x)
class(x)
Until these questions are answered, every next step is guesswork.
Same Data, Different Objects, Different Truths
R allows the same values to carry radically different meanings.
x <- c(1, 2, 3)
y <- factor(c(1, 2, 3))
To a human eye, these look interchangeable.
To R, they are not even related.
typeof(x); class(x)
typeof(y); class(y)
This is not pedantry.
This is how silent analytical errors are born.
A factor is a claim about categories.
A numeric vector is a claim about magnitude.
Confuse the two, and your analysis becomes fiction with confidence intervals.
Transformation Creates New States of Meaning
R encourages a bias toward immutability.
x <- c(2, 4, 6)
y <- x / 2
Nothing was “updated.”
A new object now exists—derived, not mutated.
This matters because reasoning requires traceability.
You should always be able to point to:
- what existed before
- what changed
- what now exists instead
Pipelines work because each step is a visible state transition, not a hidden side effect.
Functions Are Object Transformers
A function in R is not an action. It is a mapping between objects.
mean(x)
Input: a numeric vector. Output: another vector—length one, but still a vector.
typeof(mean(x))
There are no special cases. Consistency beats convenience.
Functions Themselves Are Objects
This is where R quietly becomes powerful.
typeof(mean)
class(mean)
A function can be:
- stored
- passed
- composed
- returned
This is why abstraction in R feels natural once you stop fighting it. You are not calling tools—you are assembling transformations.
Inspection Is a Habit, Not a Phase
Experienced R users inspect constantly:
str()
class()
length()
names()
Not because they forget—but because they refuse to assume.
Assumption is the enemy of reproducibility.
Inspection is its antidote.
Every analysis failure in R can be traced to a single mistake:
You acted before understanding the object.
R is unforgiving—but fair. Respect the object, and the language aligns. Ignore it, and nothing downstream will save you.
Artikel Terkait
Structure Precedes Power
Power in R does not come from knowing more functions. It comes from knowing what you are holding before you touch it.
Lists: Where Complexity Lives
Lists are where R stops pretending to be easy and reveals what it actually is: a language built to represent complex, nested, uneven reality without flattening it.
Tables Are Coordinated Vectors, Not Grids
A data frame is nothing more—and nothing less—than a collection of vectors that: - share the same length - are aligned by position - are interpreted together