Matthew,<div><br></div><div>Thanks for the reply. It turns out that the problem I was reporting was in data.table version 1.6.6, R version 2.13.1. The issue is fixed in 1.7.1, the current version. I should know better than to report problems without version numbers (and without checking if there is a more recent version). Sorry for the noise.</div>
<div><br></div><div> -s<br><br><div class="gmail_quote">On Fri, Oct 28, 2011 at 20:53, Matthew Dowle <span dir="ltr"><<a href="mailto:mdowle@mdowle.plus.com">mdowle@mdowle.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, 2011-10-28 at 18:46 -0400, Stavros Macrakis wrote:<br>
> > t1 <- data.table(a=1:3,b=1/(1:3))<br>
> > t1[1,2]<- 99<br>
><br>
><br>
> Shouldn't this give an error?<br>
</div>Why? What else could it mean other than what it does :<br>
> t1<br>
a b<br>
[1,] 1 1.0000000<br>
[2,] 2 0.5000000<br>
[3,] 3 0.3333333<br>
> t1[1,2]<- 99<br>
> t1<br>
a b<br>
[1,] 1 99.0000000<br>
[2,] 2 0.5000000<br>
[3,] 3 0.3333333<br>
<div class="im"><br>
<br>
> With with=T (the default), this doesn't make sense, and the resulting<br>
> DT is not valid:<br>
<br>
</div>The [<- method is different to the [ method of data.table.<br>
<div class="im"><br>
><br>
><br>
> > t1<br>
> Error in data.table(lapply(x, function(x) { :<br>
> every input must have at least one value, unless all columns are<br>
> empty<br>
<br>
</div>I can't reproduce this. I got a different (correct) error :<br>
> t1[1,2,with=FALSE]<- 99<br>
Error in `[<-.data.table`(`*tmp*`, 1, 2, with = FALSE, value = 99) :<br>
unused argument(s) (with = FALSE)<br>
<div class="im"><br>
<br>
><br>
><br>
> In fact, I'm not sure how to modify an individual cell in a DT:<br>
<br>
</div>It already did, above. But, := is faster and shorter than <-.<br>
<div class="im"><br>
><br>
><br>
> > t1 <- data.table(a=1:3,b=1/(1:3))<br>
> > t1[1,2,with=F]<- 99<br>
> Error in `[<-.data.table`(`*tmp*`, 1, 2, with = F, value = 99) :<br>
> unused argument(s) (with = F)<br>
><br>
><br>
> On the other hand, you can apparently modify an entire column:<br>
><br>
><br>
> t1 <- data.table(a=1:3,b=1/(1:3))<br>
> > t1$b <- 11:13<br>
> > t1<br>
> a b<br>
> [1,] 1 11<br>
> [2,] 2 12<br>
> [3,] 3 13<br>
><br>
><br>
> And modifying a key column very sensibly makes it no longer a key:<br>
><br>
><br>
> > t2 <- data.table(a=1:3,b=1/(1:3),key="a")<br>
> > key(t2)<br>
> [1] "a"<br>
> > t2$a <- 11:13<br>
> > key(t2)<br>
> NULL<br>
><br>
<br>
</div>Yes, all intended and correct, iiuc.<br>
<br>
> _______________________________________________<br>
> datatable-help mailing list<br>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
<br>
<br>
</blockquote></div><br></div>