(R-lang.info)Objects


Next: Evaluation of expressions Prev: Introduction Up: Top
Enter node , (file) or (file)node

2 Objects
*********

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.

   In this chapter we provide preliminary descriptions of the various
data structures provided in R. More detailed discussions of many of them
will be found in the subsequent chapters.  The R specific function
'typeof' returns the "type" of an R object.  Note that in the C code
underlying R, all objects are pointers to a structure with typedef
'SEXPREC'; the different R data types are represented in C by
'SEXPTYPE', which determines how the information in the various parts of
the structure is used.

   The following table describes the possible values returned by
'typeof' and what they are.

     '"NULL"'       NULL
     '"symbol"'     a variable name
     '"pairlist"'   a pairlist object (mainly internal)
     '"closure"'    a function
     '"environment"'an environment
     '"promise"'    an object used to implement lazy evaluation
     '"language"'   an R language construct
     '"special"'    an internal function that does not evaluate its
                    arguments
     '"builtin"'    an internal function that evaluates its
                    arguments
     '"char"'       a 'scalar' string object (internal only) ***
     '"logical"'    a vector containing logical values
     '"integer"'    a vector containing integer values
     '"double"'     a vector containing real values
     '"complex"'    a vector containing complex values
     '"character"'  a vector containing character values
     '"..."'        the special variable length argument ***
     '"any"'        a special type that matches all types: there are
                    no objects of this type
     '"expression"' an expression object
     '"list"'       a list
     '"bytecode"'   byte code (internal only) ***
     '"externalptr"'an external pointer object
     '"weakref"'    a weak reference object
     '"raw"'        a vector containing bytes
     '"S4"'         an S4 object which is not a simple object

Users cannot easily get hold of objects of types marked with a '***'.

   Function 'mode' gives information about the "mode" of an object in
the sense of Becker, Chambers & Wilks (1988), and is more compatible
with other implementations of the S language.  Finally, the function
'storage.mode' returns the "storage mode" of its argument in the sense
of Becker et al. (1988).  It is generally used when calling functions
written in another language, such as C or FORTRAN, to ensure that R
objects have the data type expected by the routine being called.  (In
the S language, vectors with integer or real values are both of mode
'"numeric"', so their storage modes need to be distinguished.)

     > x <- 1:3
     > typeof(x)
     [1] "integer"
     > mode(x)
     [1] "numeric"
     > storage.mode(x)
     [1] "integer"

   R objects are often coerced to different types during computations.
There are also many functions available to perform explicit coercion.
When programming in the R language the type of an object generally
doesn't affect the computations, however, when dealing with foreign
languages or the operating system it is often necessary to ensure that
an object is of the correct type.

Basic types
Attributes
Special compound objects

automatically generated by info2www version 1.2.2.9