R - (Object|Variable|Symbol)

> Procedural Languages > R

1 - About

R provides a number of specialized objects. They are created (instantiated), used and referenced through variable (known as symbol).

  • When you read the term object in the documentation, you can interchange it with the term variable (known as symbol)
  • The variable (known as symbol) are themselves objects

The variable (symbol) references objects.

The symbols are themselves objects and has wide ranging effects.

R have some reserved variable (system variable)


3 - Example

  • Numeric
> x=1
# Implicit printing of the variable
> x   
[1] 1
# Explicit printing of the variable
> print(x)

The [1] indicates that x is of the vector class

> x+x
[1] 2

4 - Structure

4.1 - Type

The type determine the internal storage and can be seen as the primitive type of R.

See R - (Datatype|Type|Storage Mode) of an object (typeof, mode)

4.2 - Class

The class properties permits R to have an object like behavior.

R supports several class (data structure) for an object:

And you can create yours.


4.3 - Attribute

All objects except the NULL object can have one or more attributes.

Common R objects attributes are:

  • the element names,
  • dim(ension) attribute (e.g. matrices, arrays)
  • dimnames: the size and the name of each dimension of the object
  • class which stores the name of the class of the object
  • user-defined attributes

Attributes of an object can be listed using the attributes() function.

# data.frame object
[1] "a" "b" "c"

[1] 1 2 3 4

[1] "data.frame"

The value of a specific attribute can be obtained using the attr() function (or NULL if the attribute is not defined).

For example,

# data.frame object
attr(x, "class")
[1] "data.frame"

5 - Management

5.1 - Rename

newname <- oldname

5.2 - List

List current objects (objects in the workspace)


ls shows you the variables

> x <- rnorm(50)
> y <- rnorm(x)
> ls()
[1] "x" "y"

5.3 - Delete

# Delete all variables for the environment
rm(list = ls())
> rm(x, y)
> ls()

5.4 - Copy

newobject <- edit(object)

5.5 - Diff

5.6 - Serialization

apropos (or find) returns a character vector of all objects matching the text searched.


6 - Functions

6.1 - Structure

Structure of an object


6.2 - Fix / Edit

# Open an editor and doesn't gives the possibility to change the definition
# Open an editor and gives the possibility to change the values.

6.3 - View


where object is an object that can be coerced to a data frame