[R] gsubfn, strapply, REGEX Problem

Johannes Graumann johannes_graumann at web.de
Tue Oct 28 14:33:42 CET 2008


Thank you! 

Joh

Gabor Grothendieck wrote:

> Have just made an improvement to the development
> version to ignore escaped left parens in the regexp
> in setting the backref default.  This improvement
> should address your problem so that this now
> works without errors:
> 
> library(gsubfn)
> # overwrite relevant function with devel version of it
> source("http://gsubfn.googlecode.com/svn/trunk/R/gsubfn.R")
> 
> strapply("S(AC,P)TVDK(8)EELVQK(8)", ".[(].{1,2}[)]|.")[[1]]
> 
> On Tue, Oct 28, 2008 at 8:53 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> The default has changed to be the negative of its prior
>> value so that would account for it.  The current
>> default is backref = -k where k is the number of left parens in
>> the regexp.  That means that it passes only the
>> back references (and not the match) if it thinks there
>> are any backreferences.  Usually this revised default
>> is what is wanted but the unusual aspect of this example
>> is that the parens don't represent back references
>> and the "wrong" default happened to work anyways.
>>
>> I guess the bottom line is that if you use parens in
>> your regexp that are not intended to be back references
>> then its important to specify backref= explicitly.
>>
>> The NEWS file in the gsubfn distribution does mention
>> the change.
>>
>> On Tue, Oct 28, 2008 at 8:32 AM, Johannes Graumann
>> <johannes_graumann at web.de> wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA512
>>>
>>> Thanks for looking at this. The "\"" was an oversight for the example,
>>> but the "backref" bit solves my problem ... I wonder whether that used
>>> to be the default and was recently changed?
>>>
>>> Thanks for your help!
>>>
>>> Joh
>>>
>>> Gabor Grothendieck wrote:
>>>
>>>> There is no quote terminating the first argument and you
>>>> need to add the backref = 0 argument so that it does
>>>> not interpret the parentheses in the regular expression
>>>> as back references.
>>>>
>>>> Its not clear to me what the intention is here so there
>>>> may be further changes needed but the ones above
>>>> result in no error message.
>>>>
>>>> On Tue, Oct 28, 2008 at 7:39 AM, Johannes Graumann
>>>> <johannes_graumann at web.de> wrote:
>>>>> Hi all,
>>>>>
>>>>> I swear this used to work:
>>>>>
>>>>> library(gsubfn)
>>>>> strapply("S(AC,P)TVDK(8)EELVQK(8), ".[(].{1,2}[)]|.")[[1]]
>>>>>
>>>>> But somewhere along the update path it stopped ... now giving me this
>>>>>
>>>>> Error in base::gsub(pattern, rs, x, ...) :
>>>>>  invalid backreference 2 in regular expression
>>>>>
>>>>> Can't figure it out. What am I doing wrong?
>>>>>
>>>>> Thanks for any hints, Joh
>>>>>
>>>>> ______________________________________________
>>>>> R-help at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/posting-guide.html and provide commented,
>>>>> minimal, self-contained, reproducible code.
>>>>>
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html and provide commented,
>>>> minimal, self-contained, reproducible code.
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.9 (GNU/Linux)
>>>
>>> iQIcBAEBCgAGBQJJBwZjAAoJEK3uDRxoATjEb9gP/ioWCERhZrLAaeIPMc1PSmVV
>>> nsWojOneSNruSESMgmocrKkOYbkPVZmmBetK9gw4sw9hLErGjy1MsebHVr40pNK2
>>> Bajm7mXJ1wbd7EDlvRfS3KpBkPvPlUmSMlp2fMoYaswcyt6Rokr3S512UlkvlLWU
>>> QNd8NMx4iRFPn3dA84SW1SqWaKIXtpTME35k1VQw0dGvv8iTgsY6pAHWkEoezuue
>>> g/tGY8kc2WjBpvVjSVDD4uAuzO9T502n1AjsUs+/bxVRBPIJJktFzkOJbhKQabuJ
>>> 2NfEX45B4Y/f1nMff5KQ1IS4LQUUzNwzvEuwHuw2CXfKnzopNUUjU3rcCaHwOIJz
>>> yecnRXpGwVX+dHaLH156voiHJqpsz7tUoIUOvAQumfwmPajK9Z/KKwLoXdXQ22gB
>>> 5469gcVBI+z31euijZMRMW12M7ZidABnHd2afxrwQRZyU9sexemzVzSdAlIpIgr5
>>> JG62rxpFY2ImmzTDncZpNik68cviB1ZLloH4twJxFk/T7DmS3x17wVofPb1yOZDq
>>> TYCvRcGIihhZ3fZM/m2qExv+bkCS80CnY1qMY+o8BmTDcp6hH64UpCQz17o/8JG9
>>> Fo8jjLRghuh1DBThL6zrzg+70UTqhNWXdBSLs/UPB1W8i1Xk+PTIFLWGigq1+3ty
>>> KoHmwgt/Bd27e2XO+leu
>>> =JlLi
>>> -----END PGP SIGNATURE-----
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html and provide commented,
>>> minimal, self-contained, reproducible code.
>>>
>>
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.



More information about the R-help mailing list