[R] function returning all arguments of current call

Wolfram Fischer wolfram at fischer-zim.ch
Thu Jun 20 16:16:18 CEST 2002


Thanks, Peter! Your solution is working as expected.

It seems that also
	f2 <- function( x=2, y=2, ... ) f1( x, y, ... )
or - to be not dependent on the order of the arguments -
	f2 <- function( x=2, y=2, ... ) f1( x=x, y=y, ... )
would help.

In my real problem I have long and variable lists
of arguments and I would be happy if I could omit
a tedious repetition of any of the arguments.

Also
	f3 <- function( z=3, x=3, ...) f1( FUN_RETURNING_ARGS() )
should work.


Is there a function analogous to match.call() but which
delivers all arguments: the args set explicitly and the
args set by default?

Wolfram


PS: There was a litte bug in the original problem description.
Here is the corrected and expanded version of the problem:
	f1 <- function( x=1, y=1, z=1 ) paste( 'x =', x, ' y =', y, ' z =', z )
	f2 <- function( x=2, y=2, ... ) f1( FUN_RETURNING_ARGS() )
	f3 <- function( z=3, y=3, ... ) f1( FUN_RETURNING_ARGS() )
	f1(10)
	#     [1] "x = 10  y = 1  z = 1"
	f2(20)
	#     [1] "x = 20  y = 2  z = 1"
	f3(30)
	#     [1] "x = 1  y = 3  z = 30"


--- In reply to: ---
>Date:    20.06.02 10:34 (+0200)
>From:    Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk>
>To:      To Uwe Ligges
>Subject: Re: [R] function returning all arguments of current call
>
> Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:
> 
> > Wolfram Fischer wrote:
> > > 
> > > Is there a FUNCTION_RETURNING_ALL_ARGS()
> > > which would enable to define functions with
> > > different default values?
> > > 
> > > f1 <- function( x=1, y=1, ... ) paste( 'x =', x, 'y =', y )
> > > f2 <- function( x=2, y=2, ... ) f2( FUN_RETURNING_ARGS() )
> > > 
> > > f1( 10 )
> > > #       [1] "x = 10, y = 1"
> > > f2( 10 )
> > > #       [1] "x = 10, y = 2"
> > 
> > formals() should do the trick:
> > 
> >   f2 <- function( x=2, y=2, ... )  formals()
> >   f2()
> 
> More likely WF is looking for 
> 
> f2 <- function( x=2, y=2, ... ) eval.parent(substitute(f1(x,y,...)))
> 
> -- 
>    O__  ---- Peter Dalgaard             Blegdamsvej 3  
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list