Re: [R] Aliases for arguments in a function

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 15 Aug 2006 - 23:16:48 EST

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

works.

On Tue, 15 Aug 2006, KKThird@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@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@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

______________________________________________
R-help@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.
Received on Tue Aug 15 23:22:28 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 16 Aug 2006 - 00:22:04 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.