[datatable-help] Comma-separated columns in by break if there are spaces

Matthew Dowle mdowle at mdowle.plus.com
Mon Apr 2 01:05:58 CEST 2012


Thanks for posting this. I'm really surprised that by="A, B" worked
before. So it wasn't intentional to change that, but what it does now
seems correct; i.e., looking for the column called " B" (starting with a
space).
Have added 3 tests:
DT = data.table("a "=1:2, "b"=3:4, " b"=5:6, v=1:6)
DT[,sum(v),by="b, b"]    # ok
DT[,sum(v),by="a , b"]   # ok
DT[,sum(v),by="b, a"]    # error: ' a' not found



On Sat, 2012-03-31 at 15:03 +0200, Christoph Jäckel wrote:
> Hi together,
> 
> 
> I use spaces when I separate columns in the by-argument, but with
> version 1.8.0 that does not work anymore:
> 
> 
> library(data.table)
> DT <- data.table(A = rep(letters[1:10], each=5),
>                  B = rep(1:10, times=5),
>                  C = rnorm(50))
> DT[, .N, by="A, B"] #does not work, but used to work before
> DT[, .N, by="A,B"]  #does work
> 
> 
> Is this on purpose? Or is this a minor bug, probably introduced when
> bug #1880 was fixed (see NEWS of v1.8.0):
> 
> 
> * 'by' was failing (bug #1880) when passed character column names
> where 
> one or more included a space. So, this now works : 
>     DT[,sum(v),by="column 1"] 
> and j retains spaces in column names rather than replacing spaces
> with 
> "."; e.g., 
>     DT[,list("a b"=1)] 
> Thanks to Yang Zhang for reporting. Tests added. As before, column
> names 
> may be back ticked in the usual R way (in i, j and by); e.g., 
>     DT[,sum(`nicely named var`+1),by=month(`long name for date
> column`)] 
> 
> 
> If it's the latter, let me know. I'll raise a bug report.
> 
> 
> Christoph
> 
> 
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help




More information about the datatable-help mailing list