Re: [Rd] slight anomaly in formals<- ? (PR#9758)

From: <ripley_at_stats.ox.ac.uk>
Date: Wed, 27 Jun 2007 08:00:34 +0200 (CEST)


On Tue, 26 Jun 2007, georgi.boshnakov_at_manchester.ac.uk wrote:

> Hi,
>
> The R input/output after the following paragraph is from a session with
> version.string R version 2.4.0 Patched (2006-11-23 r39958).

Which is not recent, but this is unchanged since.

The problem is the definition:

> `formals<-`

function (fun, envir = environment(fun), value) as.function(c(value, body(fun)), envir)
<environment: namespace:base>

and

> c(x, NULL)

$a

$b
[1] 4

$c

I've fixed this for 2.6.0 (it is not critical enough for 2.5.1 due tomorrow). If you need the defn for your version, it is

`formals<-` <- function (fun, envir = environment(fun), value) {

     bd <- body(fun)
     as.function(c(value, if(is.null(bd)) list(bd) else bd), envir)
}

>
> The last element, x$c, of x has no value and after the assignment of x
> to the formals of f, x$c does not become a formal argument of f. The
> second assignment does the job. It seems that x$c actually becomes the
> body of f after the first assignment. There is no problem if the body of
> f is not NULL (this probably explains why the second time the assignment
> to the formals of f works as expected.
>
>> x <- alist(a=,b=,c=)
>> x$b <- 4

Or just x <- alist(a=,b=4,c=)

>> f <- function(x) NULL
>> f
> function(x) NULL
>> formals(f) <- x
>> f
> function (a, b = 4)
>
>> formals(f) <- x
>> f
> function (a, b = 4, c)
>
>> body(f)
>
>
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 27 Jun 2007 - 06:03:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Jun 2007 - 07:35:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.