[datatable-help] Wonder whether there is an easier way to changepart of data.table values

Harish harishv_99 at yahoo.com
Fri Aug 6 10:13:25 CEST 2010


Thought #1 -- Consistency
----------

Quick thought -- would it be more consistent if the interface took in the name of the variable directly rather than a string?

In other words, would
   dt[,a] <- "b"
be more consistent with the existing data.table interface than
   dt[,"a"] <- "b"
?

Then again, taking in a string of the column name avoids the temptation to having complex expressions (like a+23*c) as the name of the column.  Although I just argued against my own point, I am curious what other people think.


Thought #2 -- Alternative interfaces suggested in past
----------

Also, there were some other messages in the past discussing having an interface similar to:
   dt[,{a = "b"}]
   dt[,{T(temp_a) = "b"; a = temp_a}]
   etc.

What are the merits of having the ability to set values integrated into the "[.data.table" function?

Regards,
Harish


--- On Mon, 8/2/10, Short, Tom <TShort at epri.com> wrote:

> From: Short, Tom <TShort at epri.com>
> Subject: Re: [datatable-help] Wonder whether there is an easier way to changepart of data.table values
> To: "Branson Owen" <branson.owen at gmail.com>, datatable-help at lists.r-forge.r-project.org
> Date: Monday, August 2, 2010, 7:28 PM
> I've just checked in versions of
> [<-.data.table and $<-.data.table that
> check for the columns adjusted and reset the key if
> appropriate. This
> brings up some incompatibilities:
> 
> (*) KEYS -- Before, you could do:
> 
> dt$key_column = anything
> 
> And it wouldn't change the status of the key. Now, the key
> will be
> nullified.
> 
> (*) ASSIGNMENT DIFFERENCE
> 
> Before: dt["a"] <- "b" meant change column a.
> Now:    dt[,"a"] <- "b" 
> 
> Now, you can do 
> dt[J("a"), "somecol"] <- 33 means assign 33 to the
> column "somecol"
> based on the key being equal to "a".
> 
> (*) QUESTIONS
> 
> - Do we need a "keep.key" argument for cases where we don't
> want the key
> nullified (the user knows the order is unaffected). This
> isn't really
> possible for dt$a[1:4] <- something.
> 
> - Is it a good idea to use data.table-style indexing for
> the i part of
> [<-.data.table? I was skeptical when Branson first asked
> (prefering
> data.frame compatibility), but it makes more sense now that
> I think
> about it.
> 
> Finally, we should put a warning in the documentation
> somewhere that
> functions that re-arrange or assign values to a data frame
> may "corrupt"
> the key of a data.table. Data.table-aware functions should
> account for
> this, but other functions may not.
> 
> - Tom
>  



      


More information about the datatable-help mailing list