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

From: Henrik Bengtsson <hb_at_stat.berkeley.edu>
Date: Wed, 03 Jun 2009 17:07:02 -0700


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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 04 Jun 2009 - 00:11:39 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 Thu 04 Jun 2009 - 06:44:20 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.

list of date sections of archive