R-ecology-lesson icon indicating copy to clipboard operation
R-ecology-lesson copied to clipboard

Possible confusion about the term `object`

Open iimog opened this issue 7 years ago • 7 comments

When working through the lesson material I noticed that what I thought of as variables was consistently called objects. Originally coming from a non R programming language I was slightly confused. So I did some research and it indeed seams to be more precise to use object instead of variable as the R language specification states:

In every computer language variables provide a means of accessing the data stored in memory. R does not provide direct access to the computer’s memory but rather provides a number of specialized data structures we will refer to as objects. These objects are referred to through symbols or variables. In R, however, the symbols are themselves objects and can be manipulated in the same way as any other object. This is different from many other languages and has wide ranging effects.

https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Objects So as the wording is already correct and consistent throughout the whole lesson this is not really an issue. But there might be others like me that get confused so it might be a good idea to point out this special meaning of object or that they are sometimes also referred to as variable in the lesson material or in the instructor notes. This might be a possible pitfall for instructors as well as learners.

iimog avatar Aug 02 '16 11:08 iimog

hi @iimog, would you be willing to write a short paragraph to include as a callout in one of the lesson?

fmichonneau avatar Jan 13 '17 18:01 fmichonneau

Whilst I think this callout is useful, I think it's currently confusing and would like to see this issue reopened.

For people who work in object-based languages, the definition of objects in R is the same as many people would expect. I think the issue here isn't a different nomenclature between R and other languages, but rather that many readers aren't used to making a distinction between objects and variables.

The R documentation uses both the words object and variable, but to refer to different things. Both of which are broadly in-line with the wikipedia definitinos of object and variable

One suggestion would be: R makes a subtle distinction between an object and a variable. However, in this lesson, we will use the word object to synonymously mean object and variable. For more information see: https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Objects

Very open to other suggestions on the wording etc.

If I'm wrong about the definition of variable and object in R, then I aplogise and hope that someone will clarify this to me.

markgdawson avatar Mar 26 '19 11:03 markgdawson

I think you're right and I'm fine with changing the wording of the call-out as you suggested.

iimog avatar Mar 27 '19 07:03 iimog

@M4rkD that sounds good to me, would you be willing to do a PR with your edits?

fmichonneau avatar Mar 27 '19 08:03 fmichonneau

Thank you for considering my suggestion, I'm happy to create a PR.

Having said that, can we do better? The following discussion is based on my understanding, and I don't claim to be an expert in R. My understanding is as follows:

Let's consider something like a <- 55.

In this case, the "object" is a vector containing the number 55. The variable is the symbol "a" which points to the object. The R documentation linked in the callout says:

objects are referred to through symbols or variables.

i.e. we should say that we assign the variable to the object.

If we do a <- 55 and then a <- 66, we are not assigining two values to the same object. We are in fact assigning a "label" or variable to two completely different objects.

In this material, we use the terminology "we assign 55 to the object". For example in the second sentence of Introduction to R we see:

However, to do useful and interesting things, we need to assign values to objects. To create an object, we need to give it a name followed by the assignment operator <-

This statement is very confusing (I think) to anyone with a prior understanding of what an object is (e.g. from another programming language). We "assign objects to variables" would be the correct way of saying this in my understanding, but I think we can reasonably just say we "assign values to variables". I think that replacing the word "object" with "variable" everywhere would result in more accurate, better material.

The software carpentry python material also faces this problem of objects/variables. In that case it seems they drop the word "object" in favour of "variable". I assume that this is because the concept of a variable (a label for a value) is much simpler to grasp than an object (an abstract representation in memory of data that may or may not have a label).

I think I would personally prefer to see the same happening in the R course, and I'm happy to adjust the material and create a PR if this is acceptable to you.

markgdawson avatar Mar 27 '19 12:03 markgdawson

Hi, I would agree with dropping the word "object" in favour of "variable". This is misleading for people who are learning R as first programming language and confusing for the ones who come from another language.

anacost avatar Apr 03 '19 15:04 anacost

I taught this lesson as part of my checkout, and the variables vs object debate did cause some confusion with the people I was instructing despite them already being familiar with R. I think for a novice, it could be even more confusing and also creates an instance of telling them information they won't really understand until later. Changing to this suggestion would probably be the best improvement:

R makes a subtle distinction between an object and a variable. However, in this lesson, we will use the word object to synonymously mean object and variable. For more information see: https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Objects

thatsciencegal avatar Jun 12 '19 18:06 thatsciencegal