Learn R Programming

scrutiny (version 1.0.0)

parens-extractors: Extract substrings from before and inside parentheses

Description

before_parens() and inside_parens() extract the part of a string before or inside parentheses, brackets, braces, or custom delimiters. split_by_parens() does the same for the columns of a data frame.

Usage

before_parens(string, delim = "parens", sep = deprecated())

inside_parens(string, delim = "parens", sep = deprecated())

Value

String vector as long as string, with surrounding whitespace removed. If a string has no opening delimiter, before_parens() returns all of it and inside_parens() returns NA. A blank part, such as the inside of "()", is NA, as is a part "NA" or "NaN".

Arguments

string

String vector.

delim

String. The pair of delimiters around the second part: "parens" (the default), "brackets", or "braces", or two custom strings, matched literally.

sep

[Deprecated] The old name of delim.

Examples

Run this code
x <- c(
  "3.72 (0.95)",
  "5.86 (2.75)",
  "3.06 (6.48)"
)

before_parens(string = x)
inside_parens(string = x)

Run the code above in your browser using DataLab