According to the manual of quote(expr):
expr: any syntactically valid R expression
While quote(x==y) returns a call x==y successfully, quote(x=y) fails:
Error in quote(x = y) : supplied argument name 'x' does not match 'expr'
Both x=y and x==y are syntactically valid R expressions, aren’t they? Why quote() fails on x=y?
As it says in
?"=":Using
=in an argument toquoteis not using it at the top level, so you have to put it in braces or parentheses, but you still have to be careful how you evaluate this expression, since the rules above will still apply.To address a comment:
As Gavin Simpson said: basically, the “top level” is when you type or run the code at the prompt and is not within a function call. Take
z = quote(expr=x)for example.z = quote(...)is evaluated at the top level, butexpr=xis not because it’s inside a function call.In
quote(expr=x),=is being used to assign the value ofxto the function argumentexpr; so you’re no longer working at the top-level, you’re constructing a function argument list (pairlist). The reasonquote(x=y)fails is becausequotedoesn’t have anxargument.The top level context is described briefly in R Internals, in Section 1.4, Contexts.