The "left hand side" of expression(x=y+z)
is actually the name of the argument you're passing to expression()
, whose value is the (unevaluated) call y + z
. So it's not a part of the expression, but is returned as the name of the list element (an expression is a list of calls, usually unnamed):
> as.list(expression(x=y+z))
$x
y + z
> names(expression(x=y+z))
[1] "x"
If, OTOH, you use the formula constructor ~
, then you get the LHS as a part of the expression:
> as.list(expression(x~y+z))
[[1]]
x ~ y + z
And you can get to it selecting the second element of the call:
> expression(x~y+z)[[1]]
x ~ y + z
> expression(x~y+z)[[1]][[1]]
`~`
> expression(x~y+z)[[1]][[2]]
x
Note: in the last line, x
is a symbol.