R replace with an assignment expression

Why do these two cases behave differently?

>substitute(c1<-100,list(c1=100))
100 <- 100

      

against

> substitute(c1=100,list(c1=100))
[1] 100

      

+2


a source to share


2 answers


As I understand it, the help assignOps

operator =

evaluates immediately. So the second expression is equivalent substitute(100,list(c1=100))

.
But you can put it in curly braces and the result is



> substitute({c1=100},list(c1=100))
{
    100 = 100
}

      

+2


a source


Since the second expression is interpreted c1 = 100

as the c1

function name argument substitute

must have a value of 100.



+2


a source







All Articles