[datatable-help] No error on invalid assignment
Stavros Macrakis
macrakis at alum.mit.edu
Sat Oct 29 00:46:24 CEST 2011
> t1 <- data.table(a=1:3,b=1/(1:3))
> t1[1,2]<- 99
Shouldn't this give an error? With with=T (the default), this doesn't make
sense, and the resulting DT is not valid:
> t1
Error in data.table(lapply(x, function(x) { :
every input must have at least one value, unless all columns are empty
In fact, I'm not sure how to modify an individual cell in a DT:
> t1 <- data.table(a=1:3,b=1/(1:3))
> t1[1,2,with=F]<- 99
Error in `[<-.data.table`(`*tmp*`, 1, 2, with = F, value = 99) :
unused argument(s) (with = F)
On the other hand, you can apparently modify an entire column:
t1 <- data.table(a=1:3,b=1/(1:3))
> t1$b <- 11:13
> t1
a b
[1,] 1 11
[2,] 2 12
[3,] 3 13
And modifying a key column very sensibly makes it no longer a key:
> t2 <- data.table(a=1:3,b=1/(1:3),key="a")
> key(t2)
[1] "a"
> t2$a <- 11:13
> key(t2)
NULL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20111028/8e0fda18/attachment.htm>
More information about the datatable-help
mailing list