[R] Aliases for arguments in a function

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 15 15:16:48 CEST 2006


foo <- function(arg1, this=that, that)
...

works.

On Tue, 15 Aug 2006, KKThird at Yahoo.Com wrote:

> Hi all. 
> 
> I have a function that I would like to use either the argument name as originally defined or another name. Within the function (and other functions) use the argument name as originally written, so I don't want to simply remove the old argument name for the new one, but simply allow the function to treat both argument names as equivalent. 
> 
> Here is an example:
> 
> foo <- function(arg1, this)
> {
> if(this < 0) stop("this must be positive")
> return(arg1/this)
> }
> 
> foo(arg1=5, this=10)
> 
> But, I also want foo() to work equivalently with the following (where 'this' and 'that 'are treated as if they were the same):
> foo(arg1=5, that=10)
> 
> Any thoughts would be appreciated.
> 
> Thanks,
> Ken
> 
>  		
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list