Learn R Programming

rapport (version 0.51)

extract.meta: Extract Template Metadata

Description

Check if template metadata field matches provided format, and return matched value in a list.

Usage

extract.meta(x, title, regex, short = NULL,
    trim.white = TRUE, mandatory = TRUE,
    default.value = NULL, field.length = 1000, ...)

Arguments

x
a string containing template metadata
title
a string containing metadata field title (can be regex-powered)
regex
a string with regular expression to match field value
short
a string with a short name for given metadata field
trim.white
a logical value indicating whether trailing and leading spaces of the given string should be removed before extraction
mandatory
a logical value indicating required field
default.value
fallback to this value if non-mandatory field is not found/malformed
field.length
maximum number of field characters (defaults to 1000)
...
additional parameters for grepl function

Value

  • a list with matched content, or NULL if the field is not required

Examples

Run this code
rapport:::extract.meta("Name: John Smith", "Name", "[[:alpha:]]+( [[:alpha:]]+)?")
    ## $name
    ## [1] "John Smith"

    rapport:::extract.meta("Name: John", "Name", "[[:alpha:]]+( [[:alpha:]]+)?")
    ## $name
    ## [1] "John"

Run the code above in your browser using DataLab