persephone
persephone

Reputation: 420

R object/assignment semantics

What is the technically correct way to talk about assignments in R?

x <- 1

assigns the name x to an object of type/mode numeric.

OR

assigns the value 1 to an object named x.

Upvotes: 0

Views: 41

Answers (1)

MrFlick
MrFlick

Reputation: 206187

I think your first description is more accurate to what R is really doing:

assigns the name x to an object of type/mode numeric.

It's important to know that objects (values) may not have names associated with them or can have more than one name associated with them. Thus it doesn't feel technically correct to say "an object named x" though that may be the mental mode most learners first start out with. That's reinforced by the choice of <- as the operator which really makes it look like you are pointing a value to a variable name rather than pointing a variable name to a value. I think the difference only really matters when you start to work with non-standard evaluation and how that really works in R. It's not unusual to start with a simplified mental model for how things work when first getting started learning a language, and then refining that model when it makes sense to incorporate additional complexity. So since you said it's for teaching purposes, you really just need to understand where your learners are and where you want them to be by the end of the teaching experience.

Upvotes: 1

Related Questions