It looks like custom attributes are lost by a DF to DT creation, and when the key info for a DT is invalidated, altered, etc... I ran into this when trying to attach some attribute info to a table that identifies column groups so that a new global variable or passing another param to functions wouldn't be needed. This worked nicely, until I had need to either modify some data in the table, which invalidates the key...<br>
<br>Was this a design decision? If so, why?<br clear="all"><br>Example::<br><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span class="Apple-style-span" style="font-family: 'DejaVu Sans Mono'; font-size: 12px;"><table class="G1dpdwhmPK ace_text-layer ace_line G1dpdwhmPF" style="font-family: Monaco,'Courier New',monospace; padding-left: 6px; padding-bottom: 4px; line-height: 1.3; border-style: none; outline-style: none; word-wrap: break-word; white-space: nowrap; cursor: text; color: rgb(255, 255, 255); font-size: 8pt ! important; width: 929px;" cellpadding="0" cellspacing="0">
<tbody><tr><td style="font-family: 'DejaVu Sans Mono'; line-height: 1.3; font-size: 8pt ! important; vertical-align: top;" align="left"><pre tabindex="0" class="G1dpdwhmFL" style="font-family: 'DejaVu Sans Mono'; font-size: 8pt ! important; outline-style: none; border-style: none; white-space: pre-wrap ! important; margin: 0px; line-height: 1.3;">
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">df <- data.frame( id=c(1:5), name= letters[1:5] )<br>
</span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(df, 'testing') <- 'keep me'<br>
</span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(df, 'testing')<br></span>[1] "keep me"<br>
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">dt <- data.table( df )<br></span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br>
</span>NULL<br><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing') <- 'keep me'<br>
</span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br></span>[1] "keep me"<br>
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">df[ 5 , 'id' ] <- 53<br></span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">dt[ 5 , 'id' ] <- 53<br>
</span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(df, 'testing')<br></span>[1] "keep me"<br>
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br></span>[1] "keep me"<br>
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">setkey(dt)<br></span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br>
</span>NULL<br><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing') <- 'keep me'<br>
</span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br></span>[1] "keep me"<br>
<span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">dt[ 5 , 'id' ] <- 3<br></span><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">attr(dt, 'testing')<br>
</span>[1] "keep me"<br><span class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">> </span><span class="G1dpdwhmMK ace_keyword" style="color: rgb(255, 157, 0);">key(dt)<br></span>NULL<br>
</pre></td></tr><tr><td style="font-family: 'DejaVu Sans Mono'; line-height: 1.3; font-size: 8pt ! important; vertical-align: top;" align="left"><table style="width: 929px;" cellpadding="0" cellspacing="0"><tbody><tr>
<td rowspan="1" style="font-family: 'DejaVu Sans Mono'; line-height: 1.3; font-size: 8pt ! important; vertical-align: top;" align="left" height="" width="1"><div class="G1dpdwhmIL ace_keyword" style="color: rgb(255, 157, 0); white-space: pre;">
> </div></td></tr></tbody></table></td></tr></tbody></table></span></span><br>-- <br>Sincerely,<br>Thell<br>