Re: [R] Retrieve regular expression groups

2010-05-05 Thread Gabor Grothendieck
Yes, you have to wrap it in a function but note that gsubfn does have facilities to make wrapping something in a function easier. If a function call is preceded by fn$ then a function in the arguments can be specified using a formula notation. For example, first we define NAify which forms a list

Re: [R] Retrieve regular expression groups

2010-05-05 Thread OKB (not okblacke)
Gabor Grothendieck wrote: > Note that X and FUN are also arguments to sapply > >> args(sapply) > function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) > NULL > > so the sapply construct in your post has the effect of applying c > to tmp, pats and strapply so the output you observe is correct

Re: [R] Retrieve regular expression groups

2010-05-02 Thread Gabor Grothendieck
There are quite a few examples in (1) ?strapply, (2) on the home page and (3) in the vignette (4) on r-help back posts if you having problems with understanding the textual description. Note that X and FUN are also arguments to sapply > args(sapply) function (X, FUN, ..., simplify = TRUE, USE.N

Re: [R] Retrieve regular expression groups

2010-05-02 Thread OKB (not okblacke)
Gabor Grothendieck wrote: > The strapply function in gsubfn does that. See > http://gsubfn.googlecode.com 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 wo

Re: [R] Retrieve regular expression groups

2010-05-02 Thread Gabor Grothendieck
The strapply function in gsubfn does that. See http://gsubfn.googlecode.com On Sun, May 2, 2010 at 6:03 PM, OKB (not okblacke) wrote: >        I'm trying to figure out how to get the text captured by capturing > groups out of a regex match.  For instance, let's say I have the pattern > "foo ([^

Re: [R] Retrieve regular expression groups

2010-05-02 Thread jim holtman
Is this what you want: > x <- "This is a foo sentence I am reading." > # only return the desired match > sub(".*foo ([^ ]+).*", "\\1 ", x) [1] "sentence" > > On Sun, May 2, 2010 at 6:03 PM, OKB (not okblacke) wrote: >I'm trying to figure out how to get the text captured by capturing > g

[R] Retrieve regular expression groups

2010-05-02 Thread OKB (not okblacke)
I'm trying to figure out how to get the text captured by capturing groups out of a regex match. For instance, let's say I have the pattern "foo ([^ ]+)" and I match it against the string "This is a foo sentence I am reading." The group in the pattern will match the word "sentence" in