From pburns at pburns.seanet.com  Sun May  1 13:24:33 2005
From: pburns at pburns.seanet.com (Patrick Burns)
Date: Sun May  1 13:25:22 2005
Subject: [Rd] formals assignment now strips attributres
In-Reply-To: <x23bt8t2w2.fsf@turmalin.kubism.ku.dk>
References: <42736B4B.3080507@pburns.seanet.com>	<x2ekcstq4f.fsf@turmalin.kubism.ku.dk>	<4273EA5A.2060503@pburns.seanet.com>
	<x23bt8t2w2.fsf@turmalin.kubism.ku.dk>
Message-ID: <4274BC71.2010805@pburns.seanet.com>

Peter Dalgaard wrote:

>Patrick Burns <pburns@pburns.seanet.com> writes:
>
>  
>
>>But the buglet gets more aggressive if you edit the function:
>>
>> > fjj <- function() x
>> > formals(fjj) <- list(x=c(a=2, b=4))
>> > fjj
>>function (x = c(2, 4))
>>x
>> > fjj()
>>a b
>>2 4
>> > fix(fjj) # do nothing but save
>> > fjj()
>>[1] 2 4
>>
>>I'm quite sure that I wouldn't have noticed if my real function were
>>not broken.
>>
>>Now I know that my functions will work if I assign the formals after I
>>edit the
>>function -- even though they look like they shouldn't work.
>>    
>>
>
>You did invite trouble by creating and subsequently a function that
>_has_ no source representation though:
>
>  
>
>>fjj <- function() x
>>formals(fjj) <- list(x=quote(c(a=2, b=4)))
>>fjj()
>>    
>>
>a b
>2 4
>  
>
>>fix(fjj)
>>fjj()
>>    
>>
>a b
>2 4
>

But the point of using 'formals' in the first place is to get a
function that is self-contained.  The real application is more
like:

formals(fjj) <- list(x = an_object)

I want 'fjj' to work even when 'an_object' is nowhere to be
found.

'formals' worked as (I) expected in versions 1.8.0
through 1.9.1 at least. 

Pat

>
>  
>


[Rd] formals assignment now strips attributres
Patrick Burns