[Rd] str() with attr(*, "names") is extremely slow for long vectors

Henrik Bengtsson (max 7Mb) hb at stat.berkeley.edu
Fri May 5 20:58:19 CEST 2006


Hi,

I noticed some time ago that, for instance, named vectors that are
really makes str() really slow when displaying the names attribute.  I
don't know exactly when this started, but it wasn't the case say 1-2
years ago.  Example (on a WinXP 1.8GHz):

> s <- 1:1000; names(s) <- s
> system.time(str(s))
 Named int [1:1000] 1 2 3 4 5 6 7 8 9 10 ...
 - attr(*, "names")= chr [1:1000] "1" "2" "3" "4" ...
[1] 0.08 0.00 0.09   NA   NA

> s <- 1:100000; names(s) <- s
> system.time(str(s))
 Named int [1:100000] 1 2 3 4 5 6 7 8 9 10 ...
 - attr(*, "names")= chr [1:100000] "1" "2" "3" "4" ...
[1] 8.82 0.00 9.11   NA   NA

I looks like all strings elements are processed although only the
first few are displayed.

Cheers

Henrik



More information about the R-devel mailing list