Suraj Gupta
2011-Sep-29 15:42 UTC
[Rd] documenting a behavior of adding named item to a list
Folks, Per a post to StackOverflow, I'm looking for an opinion on whether something should be documented: When adding a named item to a list, its guaranteed that the item will be added to the end of the list. SO post: http://stackoverflow.com/questions/7599349/adding-named-item-to-list-guaranteed-to-append-to-end-of-list/7599610#7599610 This is my first email to r-devel, so I hope this is an appropriate question. -Suraj [[alternative HTML version deleted]]
Duncan Murdoch
2011-Sep-30 13:56 UTC
[Rd] documenting a behavior of adding named item to a list
On 29/09/2011 11:42 AM, Suraj Gupta wrote:> Folks, > > Per a post to StackOverflow, I'm looking for an opinion on whether something > should be documented: > When adding a named item to a list, its guaranteed that the item will be > added to the end of the list.I'd say not. There's an easy way to guarantee the order: instead of using mylist$newname <- 1 use mylist <- c(mylist, newname=1) The former construction doesn't necessarily put it last, only when newname is a new name. The latter guarantees that it goes last. Currently, you can do something like this: x <- list(1) # one element list x[[10]] <- 10 # grows x to a 10 element list, filling in NULLs in positions 2 to 9 x$newname <- 11 # puts the newname in the 11th position It's not obvious to me that the newname shouldn't go into the 2nd position (if I ignore the comments). I wouldn't want to rule that out as a future change. Duncan Murdoch> SO post: > http://stackoverflow.com/questions/7599349/adding-named-item-to-list-guaranteed-to-append-to-end-of-list/7599610#7599610 > > This is my first email to r-devel, so I hope this is an appropriate > question. > > -Suraj > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel