q1 <- quote(1)
is_lang(q1)
is_atomic(q1)
q2 <- quote(x)
is_lang(q2)
is_name(q2)
q3 <- quote(x + 1)
is_lang(q3)
is_call(q3)
# Atomic language objects are the terminating nodes of a call
# tree: NULL or a scalar atomic vector:
is_literal("string")
is_literal(NULL)
is_literal(letters)
is_literal(quote(call()))
# Literals have the property of being self-quoting:
identical("foo", quote("foo"))
identical(1L, quote(1L))
identical(NULL, quote(NULL))
# They can be evaluated within the empty environment:
eval(quote(1L), empty_env())
# Whereas it would fail for non-atomic language objects:
# eval(quote(c(1L, 2L)), empty_env())
# Pairlists are also language objects representing argument lists.
# You will usually encounter them with extracted formals:
fmls <- formals(is_lang)
typeof(fmls)
is_lang(fmls)
# You can also extract call arguments as a pairlist:
call_args_lsp(quote(fn(arg1, arg2 = "foo")))
Run the code above in your browser using DataCamp Workspace