| is_lang {rlang} | R Documentation |
This function tests if x is a call (or language
object). This is a pattern-matching predicate that will
return FALSE if name and n are supplied and the call does not
match these properties. is_unary_lang() and is_binary_lang()
hardcode n to 1 and 2.
is_lang(x, name = NULL, n = NULL, ns = NULL) is_unary_lang(x, name = NULL, ns = NULL) is_binary_lang(x, name = NULL, ns = NULL)
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 |
n |
An optional number of arguments that the call should match. |
ns |
The namespace of the call. If |
is_lang(quote(foo(bar)))
# You can pattern-match the call with additional arguments:
is_lang(quote(foo(bar)), "foo")
is_lang(quote(foo(bar)), "bar")
is_lang(quote(foo(bar)), quote(foo))
# Match the number of arguments with is_lang():
is_lang(quote(foo(bar)), "foo", 1)
is_lang(quote(foo(bar)), "foo", 2)
# Or more specifically:
is_unary_lang(quote(foo(bar)))
is_unary_lang(quote(+3))
is_unary_lang(quote(1 + 3))
is_binary_lang(quote(1 + 3))
# By default, namespaced calls are tested unqualified:
ns_expr <- quote(base::list())
is_lang(ns_expr, "list")
# You can also specify whether the call shouldn't be namespaced by
# supplying an empty string:
is_lang(ns_expr, "list", ns = "")
# Or if it should have a namespace:
is_lang(ns_expr, "list", ns = "utils")
is_lang(ns_expr, "list", ns = "base")
# The name argument is vectorised so you can supply a list of names
# to match with:
is_lang(quote(foo(bar)), c("bar", "baz"))
is_lang(quote(foo(bar)), c("bar", "foo"))
is_lang(quote(base::list), c("::", ":::", "$", "@"))