Skip to content

duplicated fails to rise correct errors (PR#13632)

2 messages · Wacek Kusnierczyk

#
Full_Name: Wacek Kusnierczyk
Version: 2.8.0 and 2.10.0 r48242
OS: Ubuntu 8.04 Linux 32 bit
Submission from: (NULL) (129.241.110.161)


In the following code:

   duplicated(data.frame(), incomparables=NA)
   # Error in if (!is.logical(incomparables) || incomparables)
.NotYetUsed("incomparables != FALSE") : 
   # missing value where TRUE/FALSE needed

the raised error is clearly not the one intended to be raised.

?duplicated says:

"
incomparables: a vector of values that cannot be compared. 'FALSE' is a
          special value, meaning that all values can be compared, and
          may be the only value accepted for methods other than the
          default.  It will be coerced internally to the same type as
          'x'.

(...)

     Values in 'incomparables' will never be marked as duplicated. This
     is intended to be used for a fairly small set of values and will
     not be efficient for a very large set.
"

However, in duplicated.data.frame (which is called when duplicated is applied to
a data frame, as above) the parameter 'incomparables' is defunct.  The
documentation fails to explain this, and it might be a good idea to improve it.

In the code for duplicated.data.frame there is an attempt to intercept any use
of the parameter 'incomparables' with a value other than FALSE and to raise an
appropriate error, but this attempt fails with, e.g., incomparables=NA.

Incidentally, the attempt to intercept incomparables != FALSE fails completely
(i.e., the call to duplicated succeeds) with certain inputs:

   duplicated(data.frame(logical=c(TRUE, TRUE)), incomparables=c(FALSE, TRUE))
   # [1] FALSE TRUE

while

   duplicated(c(TRUE, TRUE), incomparables=c(FALSE, TRUE))
   # [1] FALSE FALSE


Regards,
vQ
#
the bug seems to have a trivial solution;  as far as i can see, it suffices to 
replace

    if (!is.logical(incomparables) || incomparables)

with

    if(!identical(incomparables, FALSE))

in all its occurrences in src/library/base/R/duplicated.R

attached is a patch created, successfully tested and installed on Ubuntu 8.04 
Linux 32 bit as follows:

    svn co https://svn.r-project.org/R/trunk trunk
    cd trunk
    # edit src/library/base/R/duplicated.R
    svn diff > duplicated.R.diff

    svn revert -R src
    patch -p0 < duplicated.R.diff
    tools/rsync-recommended
    ./configure
    make
    make check

and now

    duplicated(data.frame(), incomparables=NA)
    # error: argument 'incomparables != FALSE' is not used (yet)

regards,
vQ
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no wrote: