Henrik Bengtsson
2009-Jun-04 00:07 UTC
[Rd] function(x, dim=dim(x)) { str(dim) } => recursive default argument reference
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
Henrik Bengtsson
2009-Jun-04 01:35 UTC
[Rd] function(x, dim=dim(x)) { str(dim) } => recursive default argument reference
My bad: http://tolstoy.newcastle.edu.au/R/e2/help/07/09/25387.html /Henrik On Wed, Jun 3, 2009 at 5:07 PM, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:> 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 >