I am learning R (I started just this week), and I've been struggling with the concepts of typeof, mode, storage.mode and class. I've been searching up and down (official R documentation, StackOverflow, Google, etc.), and I haven't been able to find any clear explanation of the difference between these. (A few StackOverflow and CrossValidated answers have not really helped clear me up.) Finally (I hope), I think I understand it, and so my question is to verify if my understanding is correct.
mode vs storage.mode: mode and storage.mode are basically the same thing, except for a tiny difference in how the "single" datatype is handled.
mode vs typeof: Very similar, except for a few differences, most notably that both (typeof "integer" and "double") = (mode "numeric"); and both (typeof "special" and "builtin" = (mode "function").
class: Class is based on R's object-oriented class hierarchy. I'm having a hard time finding this graphically laid out, but the best I've been able to find is this diagram:
(If anyone can point me to a more accurate R class hierarchy, I'll replace it.)
Although the class names don't correspond exactly with the results of the R class() function, I believe the hierarchy is basically accurate. My understanding is that the "class" of an object--that is, the result of the class() function--is the root class in the hierarchy. So, for example, "Vector" is not a root class and so it never shows up as the result of the class() function. The root class might rather be "StrVector" ("character") or "BoolVector" ("logical"). In contrast, "Matrix" is itself a root class; hence, its class is "matrix".
Apparently, R supports multiple inheritance, and so some objects can have more than one class.
typeof/mode/storage.mode vs class: This is what was hardest part for me to understand. My understanding now is this: typeof/mode/storage.mode (which I will refer to henceforth simply as "mode") is basically the most complex datatype that an R object can hold as one of its values. So, for example, since matrixes, arrays and vectors can hold only one vector datatype, their mode (that is, the most complex datatype they can hold) is typically numeric, character or logical, even though their class (their position in the class hierarchy) is something completely different.
Where this gets most interesting (that is, confusing) is with objects like lists. A mode of "list" means that each value in the object can itself be a list (that is, an object that can hold diverse datatypes). Thus, regardless of if the class itself is "list", there are multiple objects (e.g. data frames) that can contain diverse values, and whose mode is therefore "list", even if their class is something else.
So, in summary, my understanding is:
typeof/mode/storage.mode (almost the same thing) is basically the most complex datatype that an R object can hold as one of its values; whereas
class is an object's object-oriented classification according to the R class hierarchy.
Is my understanding accurate? If not, could someone please give a more accurate explanation?