[R] Retrieve regular expression groups
OKB (not okblacke)
brenbarn at brenbarn.net
Mon May 3 02:20:50 CEST 2010
Gabor Grothendieck wrote:
> The strapply function in gsubfn does that. See
Ah, thanks. The documentation for that function is pretty
difficult to grasp, but I think I figured it out. . . almost. However,
for some reason I can't seem to make strapply work inside an sapply (to
do multiple regex searches over the same data). For instance, take a
look at this toy setup.
 "([^ ]+) .i. ([^ ]+)" "([^ ]+) ..g ([^ ]+)"
 "this is a big test" "this is a pig test" "this is a lim test"
"this is a non test" "this is a big foolio"
 "this is a wig foolio" "this is a fog test" "this is a bog test"
With these data, strapply(tmp, pats, c) works as expected, as
does strapply(tmp, pats, c). However, this doesn't work:
sapply(pats, strapply, X=tmp, FUN=c)
Instead it returns a strange table, some of whose elements contain the
code of strapply itself. Also, the above code gives different results
depending on whether I specify "X=tmp" or simply "tmp" as the third
argument. Shouldn't these be the same, since X is the first argument of
strapply? Any idea what's going on here?
--OKB (not okblacke)
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
More information about the R-help