[Rd] duplicated fails to rise correct errors (PR#13632)

2009-03-30 Thread waku
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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] duplicated fails to rise correct errors (PR#13632)

2009-03-30 Thread Wacek Kusnierczyk
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.kusnierc...@idi.ntnu.no wrote:
 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

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
   


-- 
---
Wacek Kusnierczyk, MD PhD

Email: w...@idi.ntnu.no
Phone: +47 73591875, +47 72574609

Department of Computer and Information Science (IDI)
Faculty of Information Technology, Mathematics and Electrical Engineering (IME)
Norwegian University of Science and Technology (NTNU)
Sem Saelands vei 7, 7491 Trondheim, Norway
Room itv303

Bioinformatics  Gene Regulation Group
Department of Cancer Research and Molecular Medicine (IKM)
Faculty of Medicine (DMF)
Norwegian University of Science and Technology (NTNU)
Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway
Room 231.05.060

---

Index: src/library/base/R/duplicated.R
===
--- src/library/base/R/duplicated.R	(revision 48242)
+++ src/library/base/R/duplicated.R	(working copy)
@@ -25,7 +25,7 @@
 
 duplicated.data.frame - function(x, incomparables = FALSE, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 duplicated(do.call(paste, c(x, sep=\r)), fromLast = fromLast)
 }
@@ -33,7 +33,7 @@
 duplicated.matrix - duplicated.array -
 function(x, incomparables = FALSE , MARGIN = 1L, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 ndim - length(dim(x))
 if (length(MARGIN)  ndim || any(MARGIN  ndim))
@@ -67,7 +67,7 @@
 
 unique.data.frame - function(x, incomparables = FALSE, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 x[!duplicated(x, fromLast = fromLast),  , drop = FALSE]
 }
@@ -75,7 +75,7 @@
 unique.matrix - unique.array -
 function(x, incomparables = FALSE , MARGIN = 1, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 ndim - length(dim(x))
 if (length(MARGIN)  1L || any(MARGIN  ndim))