R Internal Structures
This chapter is the beginnings of documentation about R internal structures. It is written for the core team and others studying the code in the src/main directory. It is a work-in-progress and should be checked against the current version of the source code. Versions for R 2.x.y contain historical comments about when features were introduced: this version is for the 3.x.y series.
1.1 SEXPs
What R users think of as variables or objects are symbols which are bound to a value. The value can be thought of as either a SEXP (a pointer), or the structure it points to, a SEXPREC (and there are alternative forms used for vectors, namely VECSXP pointing to VECTOR_SEXPREC structures). So the basic building blocks of R objects are often called nodes, meaning SEXPRECs or VECTOR_SEXPRECs.
Note that the internal structure of the SEXPREC is not made available to R Extensions: rather SEXP is an opaque pointer, and the internals can only be accessed by the functions provided.
Both types of node structure have as their first three fields a 64-bit sxpinfo header and then three pointers (to the attributes and the previous and next node in a doubly-linked list), and then some further fields. On a 32-bit platform a node1 occupies 32 bytes: on a 64-bit platform typically 56 bytes (depending on alignment constraints).
The first five bits of the sxpinfo header specify one of up to 32 SEXPTYPEs.