[datatable-help] Not getting behavior described in FAQ

Matthew Dowle mdowle at mdowle.plus.com
Wed Jun 16 02:23:30 CEST 2010


On Fri, 2010-05-07 at 09:59 -0700, Short, Tom wrote:
> > -----Original Message-----
> > On Behalf Of Harish
> > Sent: Friday, May 07, 2010 11:08 AM
> > To: datatable-help at lists.r-forge.r-project.org
> > Subject: [datatable-help] Not getting behavior described in FAQ
> >

> > *** Question #2 ***
> > For some reason, FAQ 1.1 and 1.2 do not work for me as described.
> > 
> > I have version 1.4 of the data.table package (downloaded from 
> > r-forge today).
> > 
> > Example:
> >    a <- as.data.table(installed.packages())
> >    a[,5]
> >    a[,"Version"]
> > 
> > ==> a[,5] does not return 5 as indicated in the FAQ 1.1, but 
> > returns the 5th column.
> > ==> a[,"Version"] does not return "Version" as indicated in 
> > the FAQ 1.2, but returns the "Version" column.
> > 
> > What is the bug -- the FAQ or the behavior of the code?
> 
> I think it's a bug in the FAQ. This was only recently
> changed. For the cases where j is a single number or character
> string, it's the same as using "with=FALSE". So,
> 
> a[,5] returns a data table consisting of the fifth column, but
> a[,5 + 0] returns the number five, and a[,5:6] returns 5:6.  
> 
> a[,"Version"] returns a data table consisting of the "Version"
> column, but a[,c("Version")] and a[,c("Version","Package")]
> return character strings.
> 

Thanks Harish for reporting that. Fixed now :

DT[,5] now returns 5 as FAQ 1.1 says, for consistency with DT[,c(5)] and
DT[,5+0].
DT[,"region"] now returns "region" as FAQ 1.2 says.

Background: a literal 5 like that can only possibly mean column 5. The
original thinking was that since user must mean column 5, allow user to
do it. But now the consistency argument with c(5) and 5+0 wins. Also we
want to discourage column lookup by number, best practice is by name,
usually.

I thanked you in the NEWS file as 'Harish V'. If you let me know your
surname off list I'll put that in.

I just picked this issue off for now. Will come back to other
outstanding in this thread and on the list another time.

Matthew





More information about the datatable-help mailing list