As what type of "thing" are various objects and functions one deals frequently with in R stored internally?

To clarify: For languages like Python it is very easy to understand conceptually how your data is stored internally: Everything is stored as an object and this uniform way of handling data makes it very to do advanced stuff like assigning new meaning to methods or writing functions that take other functions as input. What I am looking for is a similar conceptual understanding for R (e.g. I presume not everything in R an object as well).

(One concrete point that I would hope to understand as a consequence of the answer to this question would be: why setting,e.g., the second column of a dataframe to NULL like sodf[2] <- NULL deletes it. This means: You don't have to answer this question particularly, but please answer in such a way that I understand how various recipes spread out on the internet for dealing dataframes actually make sense.)

Also, please don't just point me to the documentation. I'm sure somewhere deep inside it is the answer, but reading the documentation is just too time consuming.


I am not sure I can go as deep as you'd like, but I can give the basics. The base types in R are C-structs. Taken from Hadley Wickham's Advanced R:

Base types

Underlying every R object is a C structure (or struct) that describes how that object is stored in memory. The struct includes the contents of the object, the information needed for memory management, and, most importantly for this section, a type. This is the base type of an R object. Base types are not really an object system because only the R core team can create new types. As a result, new base types are added very rarely: the most recent change, in 2011, added two exotic types that you never see in R, but are useful for diagnosing memory problems (NEWSXP and FREESXP). Prior to that, the last type added was a special base type for S4 objects (S4SXP) in 2005.

One layer higher (or at least different in parallel to the C base types), R itself has a few Object Oriented Systems at work. Major data containers that you likely use, such as vectors, dataframe, methods are going to be of type S3. The newer major object system defines S4 objects. There is a great overview on Hadley's webpage

Things such as removing a column if it is set to NULL (as opposed to Panda's approach, of making each column take that value) I would guess are design choices. It is likely more common to drop a column than it is to fill it with null-values - in the context of 99% of the algorithms R packages the null values would simply be ignored anyway. So for convenience; not that DF.drop() in Pandas is a major inconvenience. This behaviour is called an idiom in this blog. They also show that assigning NULL to a vector element also deletes that element. Additionally, NULL and NA behave differently: NA is a missing value, NULL is not!

IMO you should take the time to at least skim some documentation. With the help of search engines and control-F, you rarely need to drudge through pages of docs to find what you are looking for.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.