From murdoch.duncan at gmail.com  Fri Oct  8 12:14:01 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Fri, 08 Oct 2010 06:14:01 -0400
Subject: [Rd] NULL assignment will change the expression's class into
 list
In-Reply-To: <AANLkTinLmOiRjZA_DhsbYwgCv=ZhQ0DoP-a3hUacG8GP@mail.gmail.com>
References: <AANLkTinLmOiRjZA_DhsbYwgCv=ZhQ0DoP-a3hUacG8GP@mail.gmail.com>
Message-ID: <4CAEEEE9.6040607@gmail.com>

Vitalie Spinu wrote:
> Hello Everyone!
>
> NULL replacement will change expression object into list:
>
>   
>> te <- expression(a=23*4, b=33-2)
>> te
>>     
> expression(a = 23 * 4, b = 33 - 2)
>
>   
>> te[["a"]] <- quote(blabla) #ok
>> te
>>     
> expression(a = blabla, b = 33 - 2)
>
>   
>> te[["a"]] <- NULL #change to list
>> te
>>     
> $b
> 33 - 2
>
> I am on w32, version 2.11.1 (2010-05-31)
>   

That's certainly an inconsistency, still present in a recent R-devel 
(but I haven't checked the latest beta).  I don't know if it's a bug:  
NULL assignments are handled specially in other situations (e.g. if te 
was a list to start, the NULL assignment would remove the "a" entry).

A simple workaround is to use

te["a"] <- expression(NULL)

or te <- te[-1]

instead, depending on what you expected to happen.

Duncan Murdoch

> Regards,
> Vitally.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] NULL assignment will change the expression's class into list
Duncan Murdoch