From bbolker at gmail.com  Mon Nov 29 14:59:09 2010
From: bbolker at gmail.com (Ben Bolker)
Date: Mon, 29 Nov 2010 13:59:09 +0000 (UTC)
Subject: [Rd] Request:  kronecker to get a sep= argument
References: <4CEEC2B0.5060203@yorku.ca>
	<Pine.LNX.4.64.1011252305130.17459@tajo.ucsd.edu>
	<Pine.LNX.4.64.1011252318340.17459@tajo.ucsd.edu>
Message-ID: <loom.20101129T145437-550@post.gmane.org>

Charles C. Berry <cberry <at> tajo.ucsd.edu> writes:

> 
> On Thu, 25 Nov 2010, Charles C. Berry wrote:
> 
> > On Thu, 25 Nov 2010, Michael Friendly wrote:
> >
> >>  kronecker, with make.dimnames=TRUE uses a hardwired sep=":" in the line
> >>
> >>             tmp <- outer(dnx[[i]], dny[[i]], FUN = "paste", sep = ":")
> >>
> >>  For an application in which dimnames arise from an n-way array, where
> >>  different dimensions have
> >>  different roles, and I would like to be able to use kronecker in the form
> >>
> >>  kronecker(A, B, make.dimnames=TRUE, sep='/')
> >>
> >>  All this requires is to change the following two lines:
> >>
> >>  kronecker <- function (X, Y, FUN = "*", make.dimnames = FALSE, sep=":"
> >>  ...)
> >>  {
> >>   ...
> >>             tmp <- outer(dnx[[i]], dny[[i]], FUN = "paste", sep = sep)
> >> }
> >> 
> >>

[snip]

> >
> > p.s. your suggestion could break code that others may have written like

[snip]

> kronecker( letters[1:3], diag(LETTERS[1:2]), paste )


  Of course, this could be fixed (if considered appropriate)

kronecker <- function (X, Y, FUN = "*", make.dimnames = FALSE, 
  name_sep=":", ...)
{
   tmp <- outer(dnx[[i]], dny[[i]], FUN = "paste", sep = name_sep)
}

  which could still break existing code in the unlikely event
that someone used a value of FUN with a 'name_sep' argument (much
less likely).  Perhaps the argument could be named .sep -- that
seems to be a standard convention in these cases for trying to
avoid previous/user-defined argument names.
  For whatever it's worth this seems like a good idea to me -- a 
small change that will increase flexibility with little cost.

  Ben Bolker



[Rd] Request: kronecker to get a sep= argument
Ben Bolker