dimname'less array breaks apply (PR#318)

maechler@stat.math.ethz.ch maechler@stat.math.ethz.ch
Thu, 11 Nov 1999 11:26:11 +0100 (MET)


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._