extract_properties: Extract Pattern-Defined Properties from Strings

View source: R/extract_properties.R

extract_propertiesR Documentation

Extract Pattern-Defined Properties from Strings

Description

Extract Pattern-Defined Properties from Strings

Usage

extract_properties(x, patterns, replacements, as_data_frame = FALSE)

Arguments

x

vector of character

patterns

vector of character

replacements

vector of character

as_data_frame

logical. If TRUE (the default is FALSE), a data frame is returned.

Examples

# Define patterns to be matched against
patterns <- c(
  "[Bb]ericht",
  "[- ](\\d+)$",
  "Abschluss",
  "Zwischen",
  "_HS$"
)

# Define property:value pairs (or even prop1:value1+prob2:value2+...)
# referring to parts of the pattern enclosed in parentheses with \1, \2, ...
replacements <- c(
  "type:report",
  "number:\\1",
  "stage:final",
  "stage:intermediate",
  "author:Sonnenberg+reviewed:true"
)

# Define strings in which to look for properties and their values
x <- c("Bericht", "Bericht 1", "Abschlussbericht", "Zwischenbericht_HS")

# Extract property values as strings
extract_properties(x = x, patterns, replacements)

# Arrange the properties in a data frame
extract_properties(x = x, patterns, replacements, as_data_frame = TRUE)

KWB-R/kwb.fakin documentation built on June 14, 2022, 2 p.m.