read.pattern: Read file or text string using a regular expression to...

Description Usage Arguments Details Value See Also Examples

View source: R/read.pattern.R

Description

Read file or text string using a regular expression to separate fields.

Usage

1
read.pattern(file, pattern, perl = FALSE, text, sep = "\01", fileEncoding = "", ...)

Arguments

file

See read.table.

pattern

A regular expression.

perl

logical. If TRUE then a perl style regular expression is expected.

text

See read.table.

sep

This should be a character that does not appear in any field. It is used for holding an intermediate form of the text.

fileEncoding

See read.table.

...

Further arguments passed to read.table.

Details

The parenthesized portions of the regular expression are extracted as fields.

Value

A data.frame.

See Also

See strapplyc, read.table.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 3 space-separated fields.  The first field may have embedded spaces.
Lines <- "this is the first field 1 2
more text 3 4
"
pat <- "^(.*) +(\\S+) +(\\S+)$"
read.pattern(text = Lines, pattern = pat, as.is = TRUE)

# 3 space-separated fields.  The last field may have embedded spaces.
Lines2 <- "1 2 this is the first field
3 4 more text
"
pat2 <- "^(\\S+) +(\\S+) +(.*)$"
read.pattern(text = Lines2, pattern = pat2, as.is = TRUE)

Example output

Loading required package: proto
Could not load tcltk.  Will use slower R code instead.
                       V1 V2 V3
1 this is the first field  1  2
2               more text  3  4
  V1 V2                      V3
1  1  2 this is the first field
2  3  4               more text

gsubfn documentation built on May 1, 2019, 8:50 p.m.