Re: [Rd] Field initialization order bug?

From: Martin Maechler <>
Date: Tue, 17 Jul 2007 19:08:03 +0200

    PD> Prof Brian Ripley wrote:

       PBR> On Mon, 16 Jul 2007, Daniel Wilhelm wrote:

>>> I believe that I may have found a bug in R. The top code sample gives

      PBR> You have 'merely' found a bug in your understanding.
      PBR> What type did you expect 'a' to be?  If you expected
      PBR> a list, that is not what happens in the first
      PBR> example, and you need

      PBR> a <- list()
      PBR> or, better,
      PBR> a <- vector("list", 2)

    PD> To be precise, you need

    PD> a <- vector("list", 2) ; names(a) <- c("field1", "field2")

    PD> or you end up with a 4-element list.

yes; and consequently, a more readable solution would start saying

   a <- list(field1 = NULL, field2 = NULL)

or equivalently (and maybe nicer looking):

   a <- list(field1 = {}, field2 = {})

Martin Maechler, ETH Zurich mailing list Received on Tue 17 Jul 2007 - 18:15:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Jul 2007 - 18:36:44 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.