[datatable-help] No error on invalid assignment

Matthew Dowle mdowle at mdowle.plus.com
Sat Oct 29 21:08:17 CEST 2011


Ok, great. No problem.
Matthew

On Sat, 2011-10-29 at 13:09 -0400, Stavros Macrakis wrote:
> Matthew,
> 
> 
> 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.
> 
> 
>             -s
> 
> On Fri, Oct 28, 2011 at 20:53, Matthew Dowle <mdowle at mdowle.plus.com>
> wrote:
>         On Fri, 2011-10-28 at 18:46 -0400, Stavros Macrakis wrote:
>         > > t1 <- data.table(a=1:3,b=1/(1:3))
>         > > t1[1,2]<- 99
>         >
>         >
>         > Shouldn't this give an error?
>         
>         Why? What else could it mean other than what it does :
>         > t1
>             a         b
>         [1,] 1 1.0000000
>         [2,] 2 0.5000000
>         [3,] 3 0.3333333
>         > t1[1,2]<- 99
>         > t1
>             a          b
>         [1,] 1 99.0000000
>         [2,] 2  0.5000000
>         [3,] 3  0.3333333
>         
>         
>         > With with=T (the default), this doesn't make sense, and the
>         resulting
>         > DT is not valid:
>         
>         
>         The [<- method is different to the [ method of data.table.
>         
>         >
>         >
>         > > t1
>         > Error in data.table(lapply(x, function(x) { :
>         >   every input must have at least one value, unless all
>         columns are
>         > empty
>         
>         
>         I can't reproduce this. I got a different (correct) error :
>         > t1[1,2,with=FALSE]<- 99
>         Error in `[<-.data.table`(`*tmp*`, 1, 2, with = FALSE, value =
>         99) :
>          unused argument(s) (with = FALSE)
>         
>         
>         >
>         >
>         > In fact, I'm not sure how to modify an individual cell in a
>         DT:
>         
>         
>         It already did, above.  But, := is faster and shorter than <-.
>         
>         >
>         >
>         > > 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
>         >
>         
>         
>         Yes, all intended and correct, iiuc.
>         
>         > _______________________________________________
>         > 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