Examples for 'rlang::is_expression'


Is an object an expression?

Aliases: is_expression is_syntactic_literal is_symbolic

Keywords:

### ** Examples

q1 <- quote(1)
is_expression(q1)
[1] TRUE
is_syntactic_literal(q1)
[1] TRUE
q2 <- quote(x)
is_expression(q2)
[1] TRUE
is_symbol(q2)
[1] TRUE
q3 <- quote(x + 1)
is_expression(q3)
[1] TRUE
is_call(q3)
[1] TRUE
# Atomic expressions are the terminating nodes of a call tree:
# NULL or a scalar atomic vector:
is_syntactic_literal("string")
[1] TRUE
is_syntactic_literal(NULL)
[1] TRUE
is_syntactic_literal(letters)
[1] FALSE
is_syntactic_literal(quote(call()))
[1] FALSE
# Parsable literals have the property of being self-quoting:
identical("foo", quote("foo"))
[1] TRUE
identical(1L, quote(1L))
[1] TRUE
identical(NULL, quote(NULL))
[1] TRUE
# Like any literals, they can be evaluated within the empty
# environment:
eval_bare(quote(1L), empty_env())
[1] 1
# Whereas it would fail for symbolic expressions:
# eval_bare(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_expression)
typeof(fmls)
[1] "pairlist"
# Since they are mostly an internal data structure, is_expression()
# returns FALSE for pairlists, so you will have to check explicitly
# for them:
is_expression(fmls)
[1] FALSE
is_pairlist(fmls)
[1] TRUE

[Package rlang version 1.1.4 Index]