On Wed, Apr 4, 2012 at 2:17 AM, Mueller, Arne <arne.mueller@novartis.com>wrote:

> Hello,
>
> It seems there's a problem with the DataFrame class when using
> "non-standard" column names (in my case strings that could be interpreted
> as numbers). Here's an example:
>
> > library(GenomicRanges)
> > df = DataFrame("1234"=1:6, "4567"=6:11)
> > df
> DataFrame with 6 rows and 2 columns
>      X1234     X4567
>  <integer> <integer>
> 1         1         6
> 2         2         7
> 3         3         8
> 4         4         9
> 5         5        10
> 6         6        11
>
> I'd like to have the names "1234" and "4567" (i.e. Without the "X" prefix)
>
> I thought I could do the same as for a data.frame – even though
> "check.names" is accepted by the constructor the object can't be printed:
>
> > df = DataFrame("1234"=1:6, "4567"=6:11, check.names=FALSE)
> > df
> DataFrame with 6 rows and 3 columns
> Error in matrix(unlist(lapply(object, function(x) paste("<", class(x),  :
>  length of 'dimnames' [2] not equal to array extent
> In addition: Warning message:
> In if (check.names) vnames <- make.names(vnames, unique = TRUE) :
>  the condition has length > 1 and only the first element will be used
>
>
The DataFrame constructor did not have a check.names argument (awaiting a
use case), so it took it as a column. In IRanges 1.15.1, I added the
check.names argument. I also fixed the show method.

Thanks,
Michael

However … the data frame was constructed successfully:
>
> > names(df)
> [1] "X1234"       "X4567"       "check.names"
> > df[,"X1234"]
> [1] 1 2 3 4 5 6
>
> You can assign the names manually, but the print (?) method will still
> prefix the names …
>
> > names(df) = c("1234", "4567")
> > df
> DataFrame with 6 rows and 2 columns
>      X1234     X4567
>  <integer> <integer>
> 1         1         6
> 2         2         7
> 3         3         8
> 4         4         9
> 5         5        10
> 6         6        11
>
> Indexing by name, however only works with the assigned names (not with the
> names shown)
>
> > df[,"X1234"]
> Error in df[, "X1234"] : selecting cols: mismatching names
> > df[,"1234"]
> [1] 1 2 3 4 5 6
>
> Is this is a bug?
>
>   Regards,
>
>   Arne
>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> Bioc-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
>

	[[alternative HTML version deleted]]

