From murdoch at stats.uwo.ca  Fri Jul 28 14:28:35 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 28 Jul 2006 08:28:35 -0400
Subject: [Rd] substitute(INDICES) in by.data.frame returns
 invalid	multi-line name (PR#9108)
In-Reply-To: <20060728115328.DCCEB19A02@slim.kubism.ku.dk>
References: <20060728115328.DCCEB19A02@slim.kubism.ku.dk>
Message-ID: <44CA02F3.3090100@stats.uwo.ca>

On 7/28/2006 7:53 AM, pkensche at cmbi.ru.nl wrote:
> Full_Name: Philip Kensche
> Version: 2.3.0

This version is obsolete, but the error does occur in the current R-patched.

> OS: Redhat Linux
> Submission from: (NULL) (131.174.88.204)
> 
> 
> Try this:
> 
> --
> x <- data.frame(the.first.column=c("A"), the.second.column=c("b"),
> the.third.column=c("d"), and.many.more.columns=c("e"))
> 
> by(x, paste(x$the.first.column, x$the.second.column, x$and.many.more.columns,
> sep="."), function (y) { print("Hello!") })
> --
> 
> The following error message is produced on my system:
> 
> Error in "names<-.default"(`*tmp*`, value = c("paste(x$the.first.column,
> x$the.second.column, x$and.many.more.columns, ",  :
>         'names' attribute [2] must be the same length as the vector [1]
> 
> Calling substitute(INDICES) after debug(by.data.frame) returns:
> --
> paste(x$the.first.column, x$the.second.column, x$and.many.more.columns,
>     sep = ".")
> --
> i.e. the sep = ... is on the next line.

The problem is that

  names(IND) <- deparse(substitute(INDICES))

wraps the long expression; a patch is to replace that line with

  names(IND) <- deparse(substitute(INDICES), width=500)

which would need a much longer line to trigger the error, or

  names(IND) <- deparse(substitute(INDICES))[1]

I'll do the latter, and look for other instances of the same sort of thing.

Duncan Murdoch



[Rd] substitute(INDICES) in by.data.frame returns invalid multi-line name (PR#9108)
Duncan Murdoch