MARGIN in base::unique.matrix() and base::unique.array()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

MARGIN in base::unique.matrix() and base::unique.array()

Hervé Pagès-2
Hi,

The man page for base::unique.matrix() and base::unique.array() says
that MARGIN is expected to be a single integer. OTOH the code in charge
of checking the user supplied MARGIN is:

     if (length(MARGIN) > ndim || any(MARGIN > ndim))
         stop(gettextf("MARGIN = %d is invalid for dim = %d",
             MARGIN, dx), domain = NA)

which doesn't really make sense.

As a consequence the user gets an obscure error message when specifying
a MARGIN that satisfies the above check but is in fact invalid:

   > unique(matrix(1:10, ncol=2), MARGIN=1:2)
   Error in args[[MARGIN]] <- !duplicated.default(temp, fromLast =
fromLast,  :
     object of type 'symbol' is not subsettable

Also the code used by the above check to generate the error message
is broken:

   > unique(matrix(1:10, ncol=2), MARGIN=1:3)
   Error in sprintf(gettext(fmt, domain = domain), ...) :
     arguments cannot be recycled to the same length

   > unique(matrix(1:10, ncol=2), MARGIN=3)
   Error in unique.matrix(matrix(1:10, ncol = 2), MARGIN = 3) :
     c("MARGIN = 3 is invalid for dim = 5", "MARGIN = 3 is invalid for
dim = 2")

Thanks,
H.

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: MARGIN in base::unique.matrix() and base::unique.array()

Kurt Hornik-5
>>>>> Hervé Pagès writes:

Thanks for spotting this.

With c74978 I just committed, we now get

R>     unique(matrix(1:10, ncol=2), MARGIN=1:3)
Error in unique.matrix(matrix(1:10, ncol = 2), MARGIN = 1:3) :
  MARGIN = 1,2,3 is invalid for dim = 5,2
Calls: unique -> unique.matrix
R>     unique(matrix(1:10, ncol=2), MARGIN=3)
Error in unique.matrix(matrix(1:10, ncol = 2), MARGIN = 3) :
  MARGIN = 3 is invalid for dim = 5,2
Calls: unique -> unique.matrix

Best
-k

> Hi,
> The man page for base::unique.matrix() and base::unique.array() says
> that MARGIN is expected to be a single integer. OTOH the code in charge
> of checking the user supplied MARGIN is:

>      if (length(MARGIN) > ndim || any(MARGIN > ndim))
>          stop(gettextf("MARGIN = %d is invalid for dim = %d",
>              MARGIN, dx), domain = NA)

> which doesn't really make sense.

> As a consequence the user gets an obscure error message when specifying
> a MARGIN that satisfies the above check but is in fact invalid:

>> unique(matrix(1:10, ncol=2), MARGIN=1:2)
>    Error in args[[MARGIN]] <- !duplicated.default(temp, fromLast =
> fromLast,  :
>      object of type 'symbol' is not subsettable

> Also the code used by the above check to generate the error message
> is broken:

>> unique(matrix(1:10, ncol=2), MARGIN=1:3)
>    Error in sprintf(gettext(fmt, domain = domain), ...) :
>      arguments cannot be recycled to the same length

>> unique(matrix(1:10, ncol=2), MARGIN=3)
>    Error in unique.matrix(matrix(1:10, ncol = 2), MARGIN = 3) :
>      c("MARGIN = 3 is invalid for dim = 5", "MARGIN = 3 is invalid for
> dim = 2")

> Thanks,
> H.

> --
> Hervé Pagès

> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024

> E-mail: [hidden email]
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319

> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel