I have just noticed (while answering this SO question
http://stackoverflow.com/questions/12024098/return-type-for-j-parameter-in-data-table/12030867#12030867
a quirk in referencing operators within a call to lapply(.SD,...)
In base r,
lapply(1:4,'+',1)
will work
however
DT <- data.table(id=rep(1:5,20), a=1:100, b=sample(1:100, 100), c=sample(1:100,
100))
DT[,lapply(.SD, '+', 1), by = id]
returns 'attempt to apply non-function'
Ensuring that the base operator is called works
DT[,lapply(.SD, base::'+', 1), by = id]
as does
DT[,lapply(.SD, Primitive('+'),1), by = id]
which is quicker
Would it be worth noting this in one of the vignettes?
Regards
Michael
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help