SoFunction
Updated on 2025-03-01

Summary of R language symbol knowledge points

symbol

When defining a variable in R, it is actually to assign a symbol to a value in the environment

x <- 1

In fact, it is to assign symbol x to a vector object with length 1 and value 1 in the global environment.

When the R interpreter evaluates an expression, it processes all symbols

If several symbols are combined into one object, R will parse into each symbol of the object

&gt; x &lt;- 1
&gt; y &lt;- 2
&gt; z &lt;- 3
&gt; 
&gt; (v &lt;- c(x, y, z))
[1] 1 2 3
&gt; 
&gt; # Since v has been defined, changing the value of x will not change the value of v accordingly&gt; x &lt;- 10
&gt; v
[1] 1 2 3

The evaluation of the expression can be delayed so that the symbol will not be parsed immediately

> x <- 1
> y <- 2
> z <- 3
> 
> v <- quote(c(x, y, z))
> eval(v)
[1] 1 2 3
> 
> x <- 5
> eval(v)
[1] 5 2 3

Use the delayedAssign function to create an allowable object so that the variable will be evaluated only when it is first used

> x <- 1
> y <- 2
> z <- 3
> delayedAssign("v", c(x, y, z))
> x <- 5
> v
[1] 5 2 3

Using promised objects in packages allows users to use objects without loading them into memory

However, it is impossible to determine whether an object is a promised object, and there is no way to know which environment it was created in.

This is the end of this article about the summary of R language symbol knowledge points. For more relevant R language symbol content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!