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

georgi.boshnakov at manchester.ac.uk georgi.boshnakov at manchester.ac.uk
Tue Jun 26 19:15:04 CEST 2007


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).

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

> x <- alist(a=,b=,c=)
> x$b <- 4
> 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)

Dr Georgi Boshnakov               tel: (+44) (0)161 306 3684
School of Mathematics             fax: (+44) (0)161 306 3669
The University of Manchester      email: Georgi.Boshnakov at manchester.ac.uk
Sackville Street
Manchester M60 1QD

More information about the R-devel mailing list