Re: [Rd] unique.default problem (PR#12551)

From: <ripley_at_stats.ox.ac.uk>
Date: Sun, 17 Aug 2008 11:40:13 +0200 (CEST)


The problem here is that there are more incomparables than x. But in any case the answer was incorrect:

> unique(rep("a", 3), "a")

[1] "a"

I've fixed both issues via a different algorithm for 2.7.2.

On Sat, 16 Aug 2008, prokaj_at_cs.elte.hu wrote:

> Full_Name: Vilmos Prokaj
> Version: R 2.7.1
> OS: windows
> Submission from: (NULL) (213.181.195.84)
>
>
> Dear developers,
>
> The following line of code (produced by a mistake) caused an infinite loop
>
> unique("a",c("a","b"))
>
> or also
>
> unique(1,1:2)
>
> I made a little investigation, and it seems to be that the following function
> from unique.c is looping infinitely
>
>
> static int isDuplicated(SEXP x, int indx, HashData *d)
> {
> int i, *h;
>
> h = INTEGER(d->HashTable);
> i = d->hash(x, indx, d);
> while (h[i] != NIL) {
> if (d->equal(x, h[i], x, indx))
> return h[i] >= 0 ? 1 : 0;
> i = (i + 1) % d->M;
> }
> h[i] = indx;
> return 0;
> }
> In this case h contains only one negative value, which causes d->equal(=requal)
> to return 0.
>
> static int requal(SEXP x, int i, SEXP y, int j)
> {
> if (i < 0 || j < 0) return 0;
> if (!ISNAN(REAL(x)[i]) && !ISNAN(REAL(y)[j]))
> return (REAL(x)[i] == REAL(y)[j]);
> else if (R_IsNA(REAL(x)[i]) && R_IsNA(REAL(y)[j])) return 1;
> else if (R_IsNaN(REAL(x)[i]) && R_IsNaN(REAL(y)[j])) return 1;
> else return 0;
> }
>
> I do not claim that the situation above is frequent or even meaningful, however
> it should not cause a crash of R.
>
> Sincerely yours
> Vilmos Prokaj
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sun 17 Aug 2008 - 09:44:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Aug 2008 - 10:36:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive