Section 9 R Object Names

9.1 Naming Rules

  • A syntactically valid object name consists of letters, numbers, dots or underscore

  • The object name must start with a letter or dot.

  • The object name must not start with a number (not even the dot followed by a number).

  • The object name cannot be the following special reserved keywords:

break, else, FALSE, for, function, if, Inf, NA, NaN, next, NULL, repeat, return, TRUE, while

  • Object name cannot include some special symbols

    • special symbols are ^, !, £, $, &, @, +, -, /, *
    • some additional special symbols are :,[, ], ~
  • R is case-sensitive: x and X are different objects

  • R will overwrite any previous information stored in an object

    • it will not ask for permission.
  • Do not use object names already available in the global environment. It will overwrite the existing data contained in those objects.

  • Do not use the following letters for the object name:

    • c, t, T, F
  • Do not use the comment character # in the object name

9.2 Examples

Identify the CORRECT R object names from the following.

myObj <- 5

my.Obj <- 5

my Obj <- 5

_myObj <- 5

!myObj <- 5

.myObj <- 5

.my.Obj <- 5

.3rd.my.Obj <- 5

my-Obj <- 5

my_Obj <- 5

my_.Obj <- 5

for.my.obj <- 5

NULL.obj <- 5

TRUE <- 5

T <- 5

F <- 1

repeat <- 5

$my.Obj <- 5

myNewObj <- 5

c <- 5