From dwilhelm at lanl.gov  Tue Jul 17 17:56:38 2007
From: dwilhelm at lanl.gov (Daniel Wilhelm)
Date: Tue, 17 Jul 2007 09:56:38 -0600
Subject: [Rd] Field initialization order bug?
In-Reply-To: <Pine.LNX.4.64.0707170821220.30535@auk.stats>
References: <p0624081dc2c19b42aa26@[128.165.72.98]>
	<Pine.LNX.4.64.0707170821220.30535@auk.stats>
Message-ID: <p0624081ec2c295ae3fcb@[128.165.72.98]>

Thank you all for clarifying that bug in my understanding! I suppose 
that I expected 'a' to be promoted to a list when indexed from NULL. 
I will be more judicious in the future when I post.

Daniel Wilhelm



>On Mon, 16 Jul 2007, Daniel Wilhelm wrote:
>
>>I believe that I may have found a bug in R. The top code sample gives
>
>You have 'merely' found a bug in your understanding.  What type did 
>you expect 'a' to be?  If you expected a list, that is not what 
>happens in the first example, and you need
>
>a <- list()
>
>or, better,
>
>a <- vector("list", 2)
>
>>an error as shown. However, by simply switching which field is
>>initialized first as in the bottom code sample, it works as expected.
>>
>>
>>This gives an error:
>>
>>
>>a <- NULL
>>a[["field1"]] <- 1
>
>Now a is numeric
>
>>a[["field2"]] <- matrix(c(2,1), 1)
>>
>>Error in a[["field2"]] <- matrix(c(2, 1), 1) :
>>	more elements supplied than there are to replace
>>
>>
>>
>>Yet, this works as expected:
>>
>>a <- NULL
>>a[["field2"]] <- matrix(c(2,1), 1)
>
>Now a is a list
>
>>a[["field1"]] <- 1
>>
>>
>>
>>Daniel Wilhelm
>>
>>______________________________________________
>>R-devel at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>--
>Brian D. Ripley,                  ripley at stats.ox.ac.uk
>Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>University of Oxford,             Tel:  +44 1865 272861 (self)
>1 South Parks Road,                     +44 1865 272866 (PA)
>Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Field initialization order bug?
Daniel Wilhelm