2.4 Expressions, Objects and Symbols
The R code is composed by expressions. Some examples of expressions:
- Assignments
- Conditional sentences
- Arithmetic operations
- …
Expressions are made up of objects and functions. Each expression is separated from another by a new line or semicolon (;).
The R code manipulates objects. Some examples of objects:
- Vectors
- Lists
- Functions
- …
Formally the variable names in R are called symbols. Thus, we assign the object to a symbol of the current environment. The environment is formed by the set of symbols in a certain context.
2.4.1 Some examples to start with
We can use R for many things, but there are certain basics that need to be learned. When we enter a code in the R console, this code will provide us with an output. Let’s look at an example: If we enter a number or a word, R will return the same number or word.
23
## [1] 23
"Baby Yoda"
## [1] "Baby Yoda"
Each of these codes we have generated is interpreted by R, sent to our computer in a low level language, and returned in an understandable format for us.
Each code can be understood as an object (not stored) that R is interpreting for us. If we want to store that objects in our computer RAM to use them later in the same R session we need to create an assignment (we assign something to a symbol). Example:
= 23
my_number = "Baby Yoda" my_character
So we can use them later. For example, let’s just print them:
print(my_number)
## [1] 23
print(my_character)
## [1] "Baby Yoda"
Notice that to assign something to a symbol we can use =
or <-
:
= 23
my_number = "Baby Yoda" my_character
print(my_number)
## [1] 23
print(my_character)
## [1] "Baby Yoda"