[Rd] proposed changes to RSiteSearch

hadley wickham h.wickham at gmail.com
Fri May 8 17:28:20 CEST 2009


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

Hadley

-- 
http://had.co.nz/



More information about the R-devel mailing list