> On 11/09/12 12:32, Matthew Dowle wrote: >>> [...] >>> I think we want column attributes. As in: all of them. The comment is >>> just one attribute. R uses attributes for all sorts of sneaky things so >>> I think it is a bad idea if we lose some of them some of the time. >> Oh I see. Please file a bug.report(package="data.table") something like: >> "Column attributes (such as 'comment') are sometimes lost." > > Done as #2270
Thanks, will do. > >> [...] >> we'd need setcomment() [or >> setlabel(), or both] to avoid that copy; adding to the set* family. >>> A set attributes that allows setting column attributes may suffice. >> Already exists: try setattr(). Works on anything. > > Documentation says it only works for x= of type data.table. The column > of a data.table will rarely be of this type....? I think we need > setcolumnattr() or similar to do what you want. But copying a single > column is not *that* bad [1], so I suggest fixing the lost attributes is > the first priority. Documentation is misleading/incomplete. setattr() accepts x of any type, as well as data.table. I'll modify #2270 to include documenting this. Thanks. > DT = data.table(a=1:3,b=4:6) > .Internal(inspect(DT)) @0x000000001e8487e0 19 VECSXP g0c7 [OBJ,NAM(2),ATT] (len=2, tl=100) @0x000000000cc6a668 13 INTSXP g0c2 [NAM(2)] (len=3, tl=0) 1,2,3 @0x000000000cc687d0 13 INTSXP g0c2 [NAM(2)] (len=3, tl=0) 4,5,6 [ ... snip attribs ... ] > setattr(DT$b,"comment","Test comment") > str(DT) Classes data.table and 'data.frame': 3 obs. of 2 variables: $ a: int 1 2 3 $ b: atomic 4 5 6 ..- attr(*, "comment")= chr "Test comment" - attr(*, ".internal.selfref")=<externalptr> > .Internal(inspect(DT)) @0x000000001e8487e0 19 VECSXP g0c7 [OBJ,NAM(2),ATT] (len=2, tl=100) @0x000000000cc6a668 13 INTSXP g0c2 [NAM(2)] (len=3, tl=0) 1,2,3 @0x000000000cc687d0 13 INTSXP g0c2 [NAM(2),ATT] (len=3, tl=0) 4,5,6 [ ... snip attribs ... ] The hex addresses are unchanged and therefore show no copy of any of the vectors was taken, but the column's attribute was changed by reference by setattr as needed. > > Allan > [1] You would typically set the attributes when you create the column > and then leave them well alone. It is only because you keep deleting > them that I keep going back and re-setting them. Ok, understood. Thanks. _______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
