[Rd] proposed changes to RSiteSearch
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri May 8 19:02:11 CEST 2009
Romain Francois wrote:
> strapply in package gsubfn brings elegance here:
>
> > txt <- '<foo>bar</foo>'
> > rx <- "<(.*?)>(.*?)</(.*?)>"
> > strapply( txt, rx, c , perl = T )
> [[1]]
> [1] "foo" "bar" "foo"
>
sure, but this does not, in any way, make it less strange that gsub is
not vectorized.
> 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
strapply
and you know why.
vQ
More information about the R-devel
mailing list