Greetings, Is there a way to create default arguments for functions? If there is, then please explain or forward me to the instructions. I could not find anything in the archives or in the manual under function or args. Thanks -- __________________________________________________________ CareerBuilder.com has over 400,000 jobs. Be smarter about your job search http://corp.mail.com/careers
Simply declare the defaults where you specify the function arguments. e.g. test <- function (x=4, y=5) x*y> test()[1] 20 Simon. Simon Blomberg, PhD Depression & Anxiety Consumer Research Unit Centre for Mental Health Research Australian National University http://www.anu.edu.au/cmhr/ Simon.Blomberg at anu.edu.au +61 (2) 6125 3379> -----Original Message----- > From: Nicholas Croglio [mailto:ncroglio at iname.com] > Sent: Tuesday, 22 July 2003 12:06 PM > To: r-help at stat.math.ethz.ch > Subject: [R] function default > > > > Greetings, > Is there a way to create default arguments for functions? > If there is, then please explain or forward me to the instructions. > I could not find anything in the archives or in the manual > under function or args. > > Thanks > -- > __________________________________________________________ > > > > CareerBuilder.com has over 400,000 jobs. Be smarter about > your job search > http://corp.mail.com/careers > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Most functions in R have default arguments, and these are
specified in the function definition. For instance, the
following function has a default argument of 10 which is
used if none is specified:
do.it <- function(n=10) { rnorm(n) }
do.it()
Regards,
Andrew C. Ward
CAPE Centre
Department of Chemical Engineering
The University of Queensland
Brisbane Qld 4072 Australia
andreww at cheque.uq.edu.au
Quoting Nicholas Croglio <ncroglio at iname.com>:
>
> Greetings,
> Is there a way to create default arguments for
> functions?
> If there is, then please explain or forward me to the
> instructions.
> I could not find anything in the archives or in the
> manual under function or args.
>
> Thanks
> --
> __________________________________________________________
>
>
>
> CareerBuilder.com has over 400,000 jobs. Be smarter about
> your job search
> http://corp.mail.com/careers
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
fun <-
function(x=2, y=3){
c(x, y)
}
fun()
should return (2, 3); "fun(1)" should return (1, 3);
"fun(y=9)" should
return (2, 9), etc.
hope this helps. spencer graves
Nicholas Croglio wrote:> Greetings,
> Is there a way to create default arguments for functions?
> If there is, then please explain or forward me to the instructions.
> I could not find anything in the archives or in the manual under function
or args.
>
> Thanks