Re: dimname'less array breaks apply (PR#318)

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: dimname'less array breaks apply (PR#318)
maechler@stat.math.ethz.ch
Date: Thu 11 Nov 1999 - 20:26:11 EST


Message-Id: <199911111026.LAA01320@pubhealth.ku.dk>

Thanks a lot, Chuck!

>>>>> "ChuckB" == Charles C Berry <cberry@tajo.ucsd.edu> writes:

>> apply(array(1:20,c(2,2,5)),2:3,function(x) x)
ChuckB> Error: length of dimnames must match that of dims

ChuckB> Changing:

ChuckB> dimnames = if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)

ChuckB> To:

ChuckB> dimnames = if (length(dn)==0) NULL else
ChuckB> if (is.null(dn.ans)) list(ans.names, NULL) else c(list(ans.names), dn.ans)

ChuckB> seems to fix this.

yes.
I've committed the patch as follows
(starting at line 59 in src/library/base/R/apply.R) :

     if(len.a > 0 && len.a %% d2 == 0)
         return(array(ans, c(len.a %/% d2, d.ans),
- dimnames = if(is.null(dn.ans)) list(ans.names,NULL)
- else c(list(ans.names), dn.ans)))
+ dimnames = if(length(dn)) {
+ if(is.null(dn.ans)) list(ans.names,NULL)
+ else c(list(ans.names), dn.ans)}))
     return(ans)

Thanks again!

Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:10 EST