1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/call.R
3\name{is_call}
4\alias{is_call}
5\title{Is object a call?}
6\usage{
7is_call(x, name = NULL, n = NULL, ns = NULL)
8}
9\arguments{
10\item{x}{An object to test. If a formula, the right-hand side is
11extracted.}
12
13\item{name}{An optional name that the call should match. It is
14passed to \code{\link[=sym]{sym()}} before matching. This argument is vectorised
15and you can supply a vector of names to match. In this case,
16\code{is_call()} returns \code{TRUE} if at least one name matches.}
17
18\item{n}{An optional number of arguments that the call should
19match.}
20
21\item{ns}{The namespace of the call. If \code{NULL}, the namespace
22doesn't participate in the pattern-matching. If an empty string
23\code{""} and \code{x} is a namespaced call, \code{is_call()} returns
24\code{FALSE}. If any other string, \code{is_call()} checks that \code{x} is
25namespaced within \code{ns}.
26
27Can be a character vector of namespaces, in which case the call
28has to match at least one of them, otherwise \code{is_call()} returns
29\code{FALSE}.}
30}
31\description{
32This function tests if \code{x} is a \link[=call2]{call}. This is a
33pattern-matching predicate that returns \code{FALSE} if \code{name} and \code{n}
34are supplied and the call does not match these properties.
35}
36\section{Life cycle}{
37
38
39\code{is_lang()} has been soft-deprecated and renamed to \code{is_call()} in
40rlang 0.2.0 and similarly for \code{is_unary_lang()} and
41\code{is_binary_lang()}. This renaming follows the general switch from
42"language" to "call" in the rlang type nomenclature. See lifecycle
43section in \code{\link[=call2]{call2()}}.
44}
45
46\examples{
47is_call(quote(foo(bar)))
48
49# You can pattern-match the call with additional arguments:
50is_call(quote(foo(bar)), "foo")
51is_call(quote(foo(bar)), "bar")
52is_call(quote(foo(bar)), quote(foo))
53
54# Match the number of arguments with is_call():
55is_call(quote(foo(bar)), "foo", 1)
56is_call(quote(foo(bar)), "foo", 2)
57
58
59# By default, namespaced calls are tested unqualified:
60ns_expr <- quote(base::list())
61is_call(ns_expr, "list")
62
63# You can also specify whether the call shouldn't be namespaced by
64# supplying an empty string:
65is_call(ns_expr, "list", ns = "")
66
67# Or if it should have a namespace:
68is_call(ns_expr, "list", ns = "utils")
69is_call(ns_expr, "list", ns = "base")
70
71# You can supply multiple namespaces:
72is_call(ns_expr, "list", ns = c("utils", "base"))
73is_call(ns_expr, "list", ns = c("utils", "stats"))
74
75# If one of them is "", unnamespaced calls will match as well:
76is_call(quote(list()), "list", ns = "base")
77is_call(quote(list()), "list", ns = c("base", ""))
78is_call(quote(base::list()), "list", ns = c("base", ""))
79
80
81# The name argument is vectorised so you can supply a list of names
82# to match with:
83is_call(quote(foo(bar)), c("bar", "baz"))
84is_call(quote(foo(bar)), c("bar", "foo"))
85is_call(quote(base::list), c("::", ":::", "$", "@"))
86}
87\seealso{
88\code{\link[=is_expression]{is_expression()}}
89}
90