Re: [R] Preserving lists in a function

2010-02-27 Thread baptiste auguie
Point well taken --- grid::gpar() is also a good example; I'll make use of your suggestion in my future coding. Best, baptiste On 27 February 2010 15:02, Barry Rowlingson wrote: > On Sat, Feb 27, 2010 at 11:29 AM, Gabor Grothendieck > wrote: >> Or use modifyList which is in the core of R. > >

Re: [R] Preserving lists in a function

2010-02-27 Thread Barry Rowlingson
On Sat, Feb 27, 2010 at 11:29 AM, Gabor Grothendieck wrote: > Or use modifyList which is in the core of R. All these solutions appear to be adding on more and more code with less and less semantics. Result: messy code which is harder to read and debug. It seems that the arguments should have p

Re: [R] Preserving lists in a function

2010-02-27 Thread Gabor Grothendieck
Or use modifyList which is in the core of R. On Sat, Feb 27, 2010 at 5:22 AM, baptiste auguie wrote: > Hi, > > I think I would follow this approach too, using updatelist() from the > reshape package, > > > updatelist <- function (x, y) > { >    common <- intersect(names(x), names(y)) >    x[commo

Re: [R] Preserving lists in a function

2010-02-27 Thread baptiste auguie
Hi, I think I would follow this approach too, using updatelist() from the reshape package, updatelist <- function (x, y) { common <- intersect(names(x), names(y)) x[common] <- y[common] x } myfunction=function(list1=NULL, list2=NULL, list3=NULL){ list1=updatelist(list(variable1=1

Re: [R] Preserving lists in a function

2010-02-26 Thread Don MacQueen
Barry explained your first puzzle, but let me add some explanation and examples. tmpfun <- function( a =3 ) {a} tmpfun() [1] 3 tmpfun(a='x') [1] "x" Inside the function, the value of the argument is whatever the user supplied. The default is replaced by what the user supplies. There i

Re: [R] Preserving lists in a function

2010-02-26 Thread Barry Rowlingson
On Fri, Feb 26, 2010 at 10:56 PM, Shang Gao wrote: > Dear R users, > > A co-worker and I are writing a function to facilitate graph plotting in R. > The function makes use of a lot of lists in its defaults. > > However, we discovered that R does not necessarily preserve the defaults if > we were

[R] Preserving lists in a function

2010-02-26 Thread Shang Gao
Dear R users, A co-worker and I are writing a function to facilitate graph plotting in R. The function makes use of a lot of lists in its defaults. However, we discovered that R does not necessarily preserve the defaults if we were to input them in the form of list() when initializing the funct