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