[Rd] formals assignment now strips attributres

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Apr 30 22:39:57 CEST 2005


Patrick Burns <pburns at 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
> fjj
function (x = c(a = 2, b = 4))
x


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list