% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/remove_paren.R
\name{remove_paren}
\alias{remove_paren}
\title{Remove Redundant Parentheses
(very very primitive version)}
\usage{
remove_paren(exp, method = 1:9, loc = 0, debug = 0)
}
\arguments{
\item{exp}{expression vector or matrix}

\item{method}{1, 2 or 3 \cr
If exp contains any logical operator, method=1 will be used.\cr}

\item{loc}{the location of the paren to be removed. \cr
Use with caution when the paren is preceded by - sign,
or exp is a vector or matrix.}

\item{debug}{= 1 to print intermediate result.}
}
\value{
A vector or matrix of the same size as the input
}
\description{
Remove Redundant Parentheses
(very very primitive version)
}
\details{
When loc > 0 is given, those parentheses located at the loc-th position
of the elements of exp will be removed.\cr
No signs will be distributed: \cr
\code{remove_paren("-(a+b)",loc=2)} will result in \code{-a+b}.
\cr

First,  (+....)  will be replaced by  (...) .\cr
When method = 1, a pair of parentheses which encloses a single term
w/o divisions will be removed. \cr
When method = 2, a pair of parentheses which is not preceded by [*/-]
and not trailed by [*/] will be removed. \cr
When method = 3, patterns like  -(-a) or -(-(a)) will be processed.
\cr\cr
Use Expand to distribute multiplicative factors.

\cr\cr
\code{method=2} may return wrong result: \cr
\code{remove_paren("-((a+b))", method=2)} becomes \code{-a+b}.
\cr
\cr
}
\examples{
remove_paren( c("(x)", "-(x)", "(x+y)", "-(x+y)") )
remove_paren( c("a*(x)*b", "a*(x+y)*b", "(-x)*a", "-(x+y)*a") )
remove_paren( c("a\%*\%(x)\%*\%b", "a\%*\%(x+y)\%*\%b", "(-x)\%*\%a", "-(x+y)\%*\%a") )
remove_paren( c("a\%@\%(x)\%*\%b", "a\%@\%(x+y)\%@\%b", "(-x)\%@\%a", "-(x+y)\%@\%a") )

exp <- "((a)) - ((a)+f(b)) + (a-b) - (x-gg(y)) + (((z+1)))"
remove_paren( exp )

exp2 <- c(exp, "(a+b)*(c)-d+1")
remove_paren( exp2 )

( temp <- And(Or("a==A","b>0"),"c") )
remove_paren(temp)

remove_paren("!(!(a))")
remove_paren("!(!(a))",loc=4)
remove_paren("!( !(a) )",loc=9)

}
