From wdunlap at tibco.com  Wed Sep 21 20:06:21 2016
From: wdunlap at tibco.com (William Dunlap)
Date: Wed, 21 Sep 2016 11:06:21 -0700
Subject: [Rd] strcapture enhancement
Message-ID: <CAF8bMcbLMdFkoUAvve7P8Y+MhRbsRE8HsWV8psK2JmOfP=fV=Q@mail.gmail.com>

The new strcapture function in R-devel is handy, capturing
the matches to the parenthesized subpatterns in a regular
expression in the columns of a data.frame, whose column
names and classes are given by the 'proto' argument.  E.g.,

> p1 <- data.frame(Name="", Number=0)
> str(strcapture("([[:alpha:]]*) +([[:digit:]]*)", c("Three 3", "Twenty
20"), proto=p1))
'data.frame':   2 obs. of  2 variables:
 $ Name  : Factor w/ 2 levels "Three","Twenty": 1 2
 $ Number: num  3 20

I think it would be even nicer if it constructed its data.frame
using the check.names=FALSE and stringsAsFactors=FALSE
arguments.  Then the names and types specified in the proto
argument would be respected instead of changing them as
in the following example

> p2 <- data.frame("The Name"="", "The Number"=0, stringsAsFactors=FALSE,
check.names=FALSE)
> str(strcapture("([[:alpha:]]*) +([[:digit:]]*)", c("Three 3", "Twenty
20"), proto=p2))
'data.frame':   2 obs. of  2 variables:
 $ The.Name  : Factor w/ 2 levels "Three","Twenty": 1 2
 $ The.Number: num  3 20


Bill Dunlap
TIBCO Software
wdunlap tibco.com

	[[alternative HTML version deleted]]



[Rd] strcapture enhancement
William Dunlap