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_call(x, name = NULL, n = 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 Can be a character vector of namespaces, in which case the call
has to match at least one of them, otherwise |
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().
#> [1] TRUE#> [1] TRUE#> [1] FALSE#> [1] TRUE#> [1] TRUE#> [1] FALSE# By default, namespaced calls are tested unqualified: ns_expr <- quote(base::list()) is_call(ns_expr, "list")#> [1] TRUE# You can also specify whether the call shouldn't be namespaced by # supplying an empty string: is_call(ns_expr, "list", ns = "")#> [1] FALSE# Or if it should have a namespace: is_call(ns_expr, "list", ns = "utils")#> [1] FALSEis_call(ns_expr, "list", ns = "base")#> [1] TRUE#> [1] TRUE#> [1] FALSE# If one of them is "", unnamespaced calls will match as well: is_call(quote(list()), "list", ns = "base")#> [1] FALSE#> [1] TRUE#> [1] TRUE# The name argument is vectorised so you can supply a list of names # to match with: is_call(quote(foo(bar)), c("bar", "baz"))#> [1] FALSE#> [1] TRUE#> [1] TRUE