From p.dalgaard at biostat.ku.dk  Sat Apr 30 14:18:08 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sat Apr 30 14:18:17 2005
Subject: [Rd] formals assignment now strips attributres
In-Reply-To: <42736B4B.3080507@pburns.seanet.com>
References: <42736B4B.3080507@pburns.seanet.com>
Message-ID: <x2ekcstq4f.fsf@turmalin.kubism.ku.dk>

Patrick Burns <pburns@pburns.seanet.com> writes:

> The assignment form of 'formals' strips attributes (or something close
> to that) from the values in the list.  This wasn't intentional, was it?
> 
> The current behavior (2.0.0 through 2.1.0 on Windows at least):
> 
>  > fjj <- function() x
>  > formals(fjj) <- list(x=c(a=2, b=4))
>  > fjj
> function (x = c(2, 4))
> x
> 
> 
> Previous behavior:
> 
>  > fjj <- function() x
>  > formals(fjj) <- list(x=c(a=2, b=4))
>  > fjj
> function (x = structure(c(2, 4), .Names = c("a", "b")))
> x

It is only a buglet in deparsing:

>  formals(fjj)
$x
a b
2 4
> fjj()
a b
2 4
> as.list(fjj)
$x
a b
2 4

[[2]]
x

BTW, why is it that we cannot deparse named vectors nicely?
> deparse(c(a=1,b=2))
[1] "structure(c(1, 2), .Names = c(\"a\", \"b\"))"
> deparse(as.list(c(a=1,b=2)))
[1] "structure(list(a = 1, b = 2), .Names = c(\"a\", \"b\"))"

Notice also that fjj constructed as above is not identical to 

function (x = c(a = 1, b = 2))
x

since the default expression is a vector in one case and  a call to "c"
in the other. This is part of the problem; you're trying to deparse
something that cannot be the result of parsing. (The existence of such
objects is a generic problem in the R (and S) language).

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


[Rd] formals assignment now strips attributres
Peter Dalgaard