% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg_formula.R
\name{arg_formula}
\alias{arg_formula}
\title{Check Formula Argument}
\usage{
arg_formula(
  x,
  one_sided = NULL,
  .arg = rlang::caller_arg(x),
  .msg = NULL,
  .call
)
}
\arguments{
\item{x}{the argument to be checked}

\item{one_sided}{\code{NULL} or \code{logical}; if \code{TRUE}, checks that \code{x} is a \code{formula} with only one side (the right side); if \code{FALSE}, checks that \code{x} is a \code{formula} with both sides; if \code{NULL} (the default), checks only that \code{x} is a \code{formula.}}

\item{.arg}{the name of the argument supplied to \code{x} to appear in error messages. The default is to extract the argument's name using \code{\link[rlang:caller_arg]{rlang::caller_arg()}}. Ignored if \code{.msg} is supplied.}

\item{.msg}{an optional alternative message to display if an error is thrown instead of the default message.}

\item{.call}{the execution environment of a currently running function, e.g. \code{.call = rlang::current_env()}. The corresponding function call is retrieved and mentioned in error messages as the source of the error. Passed to \code{\link[=err]{err()}}. Set to \code{NULL} to omit call information. The default is to search along the call stack for the first user-facing function in another package, if any.}
}
\value{
Returns \code{NULL} invisibly if an error is not thrown.
}
\description{
Checks whether an argument is a \code{\link{formula}}.
}
\examples{
form1 <- ~a + b
form2 <- y ~ a + b
not_form <- 1:3

try(arg_formula(form1))    # No error
try(arg_formula(form2))    # No error
try(arg_formula(not_form)) # Error: not a formula

try(arg_formula(form1,
                one_sided = TRUE)) # No error
try(arg_formula(form2,
                one_sided = TRUE)) # Error, not one-sided

try(arg_formula(form1,
                one_sided = FALSE)) # Error, only one-sided
try(arg_formula(form2,
                one_sided = FALSE)) # No error
}
\seealso{
\code{\link[rlang:is_formula]{rlang::is_formula()}}, \code{\link[=arg_is]{arg_is()}}
}
