From hb at stat.berkeley.edu  Thu Jun  4 02:07:02 2009
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Wed, 3 Jun 2009 17:07:02 -0700
Subject: [Rd] function(x,
	dim=dim(x)) { str(dim) } => recursive default argument 	reference
Message-ID: <59d7961d0906031707v22dbf065t8d96d927fd7c1d31@mail.gmail.com>

Is the following a bug?

Rterm -vanilla

> foo <- function(x, dim=dim(x)) { str(dim) }
> foo(1:2)
Error in str(dim) :
  promise already under evaluation: recursive default argument
reference or earlier problems?
> foo(x=1:2)
Error in str(dim) :
  promise already under evaluation: recursive default argument
reference or earlier problems?

But, this works:

> foo <- function(x, dim2=dim(x)) { str(dim2) }
> foo(1:2)
 NULL

> foo <- function(x, dim=base::dim(x)) { str(dim) }
> foo(1:2)
 NULL


> sessionInfo()
R version 2.9.0 Patched (2009-05-28 r48680)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MON
ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

/Henrik



[Rd] function(x, dim=dim(x)) { str(dim) } => recursive default argument reference
Henrik Bengtsson