Learn R Programming

rlang (version 0.2.2)

is_call: Is object a call?

Description

This function tests if x is a call. This is a pattern-matching predicate that returns FALSE if name and n are supplied and the call does not match these properties. is_unary_call() and is_binary_call() hardcode n to 1 and 2.

Usage

is_call(x, name = NULL, n = NULL, ns = NULL)

Arguments

x

An object to test. If a formula, the right-hand side is extracted.

name

An optional name that the call should match. It is passed to sym() before matching. This argument is vectorised and you can supply a vector of names to match. In this case, is_call() returns TRUE if at least one name matches.

n

An optional number of arguments that the call should match.

ns

The namespace of the call. If NULL, the namespace doesn't participate in the pattern-matching. If an empty string "" and x is a namespaced call, is_call() returns FALSE. If any other string, is_call() checks that x is namespaced within ns.

Life cycle

is_lang() has been soft-deprecated and renamed to is_call() in rlang 0.2.0 and similarly for is_unary_lang() and is_binary_lang(). This renaming follows the general switch from "language" to "call" in the rlang type nomenclature. See lifecycle section in call2().

See Also

is_expression()

Examples

Run this code
# NOT RUN {
is_call(quote(foo(bar)))

# You can pattern-match the call with additional arguments:
is_call(quote(foo(bar)), "foo")
is_call(quote(foo(bar)), "bar")
is_call(quote(foo(bar)), quote(foo))

# Match the number of arguments with is_call():
is_call(quote(foo(bar)), "foo", 1)
is_call(quote(foo(bar)), "foo", 2)


# By default, namespaced calls are tested unqualified:
ns_expr <- quote(base::list())
is_call(ns_expr, "list")

# You can also specify whether the call shouldn't be namespaced by
# supplying an empty string:
is_call(ns_expr, "list", ns = "")

# Or if it should have a namespace:
is_call(ns_expr, "list", ns = "utils")
is_call(ns_expr, "list", ns = "base")


# The name argument is vectorised so you can supply a list of names
# to match with:
is_call(quote(foo(bar)), c("bar", "baz"))
is_call(quote(foo(bar)), c("bar", "foo"))
is_call(quote(base::list), c("::", ":::", "$", "@"))
# }

Run the code above in your browser using DataLab