<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">I have just noticed (while answering this SO question
<div><a href="http://stackoverflow.com/questions/12024098/return-type-for-j-parameter-in-data-table/12030867#12030867" target="_blank">http://stackoverflow.com/questions/12024098/return-type-for-j-parameter-in-data-table/12030867#12030867</a></div>
<div><br>
</div>
<div>a quirk in referencing operators within a call to lapply(.SD,...)</div>
<div><br>
</div>
<div>In base r, </div>
<div><br>
</div>
<div>lapply(1:4,'+',1) </div>
<div><br>
</div>
<div>will work </div>
<div><br>
</div>
<div>however</div>
<div><br>
</div>
<div>DT <- data.table(id=rep(1:5,20), a=1:100, b=sample(1:100, 100), c=sample(1:100, 100))</div>
<div><br>
</div>
<div>DT[,lapply(.SD, '+', 1), by = id]</div>
<div><br>
</div>
<div>returns 'attempt to apply non-function'</div>
<div><br>
</div>
<div>Ensuring that the base operator is called works</div>
<div><br>
</div>
<div>DT[,lapply(.SD, base::'+', 1), by = id] </div>
<div><br>
</div>
<div>as does </div>
<div><br>
</div>
<div>DT[,lapply(.SD, Primitive('+'),1), by = id]</div>
<div><br>
</div>
<div>which is quicker</div>
<div><br>
</div>
<div>Would it be worth noting this in one of the vignettes?</div>
<div><br>
</div>
<div>Regards</div>
<div><br>
</div>
<div>Michael</div>
<div><br>
<div><br>
</div>
</div>
</div>
</body>
</html>