Examples for 'rlang::is_call'


Is object a call?

Aliases: is_call

Keywords:

### ** Examples

is_call(quote(foo(bar)))
[1] TRUE
# You can pattern-match the call with additional arguments:
is_call(quote(foo(bar)), "foo")
[1] TRUE
is_call(quote(foo(bar)), "bar")
[1] FALSE
is_call(quote(foo(bar)), quote(foo))
[1] TRUE
# Match the number of arguments with is_call():
is_call(quote(foo(bar)), "foo", 1)
[1] TRUE
is_call(quote(foo(bar)), "foo", 2)
[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] FALSE
is_call(ns_expr, "list", ns = "base")
[1] TRUE
# You can supply multiple namespaces:
is_call(ns_expr, "list", ns = c("utils", "base"))
[1] TRUE
is_call(ns_expr, "list", ns = c("utils", "stats"))
[1] FALSE
# If one of them is "", unnamespaced calls will match as well:
is_call(quote(list()), "list", ns = "base")
[1] FALSE
is_call(quote(list()), "list", ns = c("base", ""))
[1] TRUE
is_call(quote(base::list()), "list", ns = c("base", ""))
[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
is_call(quote(foo(bar)), c("bar", "foo"))
[1] TRUE
is_call(quote(base::list), c("::", ":::", "$", "@"))
[1] TRUE

[Package rlang version 1.1.4 Index]