From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Fri May  8 19:25:29 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Fri, 08 May 2009 19:25:29 +0200
Subject: [Rd] proposed changes to RSiteSearch
In-Reply-To: <f8e6ff050905080828o3bbe9d0w147f26c5fdc1677b@mail.gmail.com>
References: <39B6DDB9048D0F4DAD42CB26AAFF0AFA07381973@usctmx1106.merck.com>	<20090507141812.GB25422@psych.upenn.edu>	<4A031A22.7080702@stats.uwo.ca>	<39B6DDB9048D0F4DAD42CB26AAFF0AFA073C46FD@usctmx1106.merck.com>	<20090507180930.GA1619@psych.upenn.edu>	<39B6DDB9048D0F4DAD42CB26AAFF0AFA073C4758@usctmx1106.merck.com>	<4A032E6F.8010001@dbmail.com>
	<4A040B66.3090803@idi.ntnu.no>	<4A044BBB.7060304@dbmail.com>
	<f8e6ff050905080828o3bbe9d0w147f26c5fdc1677b@mail.gmail.com>
Message-ID: <4A046B09.5040308@idi.ntnu.no>

hadley wickham wrote:
> On Fri, May 8, 2009 at 10:11 AM, Romain Francois
> <romain.francois at dbmail.com> wrote:
>   
>> strapply in package gsubfn brings elegance here:
>>
>>     
>>> txt <- '<foo>bar</foo>'
>>> rx <- "<(.*?)>(.*?)</(.*?)>"
>>> strapply( txt, rx, c , perl = T )
>>>       
>> [[1]]
>> [1] "foo" "bar" "foo"
>>
>> Too bad you have to pay this on performance:
>>
>>     
>>> txt <- rep( '<foo>bar</foo>', 1000 )
>>> rx <- "<(.*?)>(.*?)</(.*?)>"
>>> system.time( out <- strapply( txt, rx, c , perl = T ) )
>>>       
>>  user  system elapsed
>>  2.923   0.005   3.063
>>     
>>> system.time( out2 <- sapply( paste('\\', 1:3, sep=''), function(x){
>>>       
>> + gsub(rx, x, txt, perl=TRUE)
>> + } ) )
>>  user  system elapsed
>>  0.011   0.000   0.011
>>
>> Not sure what the right play i
>>     
>
> For me:
>
>   
>> system.time( out <- strapply( txt, rx, c , perl = T ) )
>>     
>    user  system elapsed
>   0.004   0.000   0.004
>
>   
>> system.time( out2 <- sapply( paste('\\', 1:3, sep=''), function(x){
>>     
> + gsub(rx, x, txt, perl=TRUE)
> + } ) )
>    user  system elapsed
>       0       0       0
>   

for me:

    txt <- '<foo>bar</foo>'
    rx <- '<(.*?)>(.*?)</(.*?)>'

    library(rbenchmark)
    benchmark(replications=1000, columns=c('test', 'elapsed'),
order='elapsed',
       sapply=sapply(paste('\\', 1:3, sep=''), function(x) gsub(rx, x,
txt, perl=TRUE)),
       mapply=mapply(gsub, rx, paste('\\', 1:3, sep=''), txt, perl=TRUE),
       strapply=strapply(txt, rx, c, perl=TRUE))
    # 2   mapply   0.151
    # 1   sapply   0.166
    # 3 strapply   1.917

vQ



[Rd] proposed changes to RSiteSearch
Wacek Kusnierczyk