locbalpar {lazy.tools}R Documentation

Return the location of the matching parenthesis

Description

Return the location of the matching parenthesis

Usage

locbalpar(exp, loc)

Arguments

exp

Input string: a single element vector.

loc

The location of the parenthesis whose matching pair will be found.

Details

loc must be positive and less than nchar(exp).
substr(exp,loc,loc) must be a opening or closing paren.
Otherwise, this function returns 0.

Value

The location of the matching paren or 0.

Examples

# Input string
#                1111111111222222222233333333
#       1234567890123456789012345678901234567
exp <- "a+([a+b]*(c*{d+e}))-(f-g) +(((<()>)) "

locbalpar( exp, 3 )
locbalpar( exp, 4 )
locbalpar( exp, 13 )
locbalpar( exp, 31 )

locbalpar( exp, regexpr( "\\(", exp ) )

# No matching paren
locbalpar( exp, 28 )

# from closing paren
locbalpar( exp, 19 )
locbalpar( exp, 17 )

# As long as substr(exp,n) is a paren, it is always true.
n <- 10; n == locbalpar( exp, locbalpar( exp, n ) )
n <- 36; n == locbalpar( exp, locbalpar( exp, n ) )


[Package lazy.tools version 0.1.3 Index]