Re: [R] optional fields in function declarations; Solved
thank you to both Adaikalavan and Patrick. on the basis of Adaikalavan example this is an example that point out my problems. log_raise=function(num, exp, base){return(log(num^exp,base))} I would like to have optional fields, so some settings to be default parameters; if I declare the function as above the operator must of course input all the variables. Finally I could fix as follow. log_raise=function(num, exp=2, base=exp){return(log(num^exp,base))} thank you helps, cheers Claudio Patrick Burns -- Initial Header --- From : Adaikalavan Ramasamy [EMAIL PROTECTED] To : [EMAIL PROTECTED] [EMAIL PROTECTED] Cc : r-help r-help@stat.math.ethz.ch Date : Sun, 20 May 2007 00:21:32 +0100 Subject : Re: [R] optional fields in function declarations Can you provide an simple example of what you want the function to do? Generally, I set some value in the default. raise - function(x, power=1){ return( x^power ) } raise(5) [1] 5 raise(5,3) [1] 125 Or you can do the same but in a slightly unclear manner. raise - function(x, power){ if(missing(power)) power - 1 return( x^power ) } I prefer the former. Regards, Adai [EMAIL PROTECTED] wrote: Dear R users, I need to create a set of function to solve some tasks. I want to leave the operator to decide whether uses default parameters or change it; so the functions may have some optional fields. I tied to use the function missing(), but it will work properly only if the optional field is decleared at last in the function. Can you give me some suggestion an some reference? thank you. Claudio -- Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom http://click.libero.it/infostrada __ 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. -- Leggi GRATIS le tue mail con il telefonino i-modeĀ di Wind http://i-mode.wind.it/ __ 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.
[R] optional fields in function declarations
Dear R users, I need to create a set of function to solve some tasks. I want to leave the operator to decide whether uses default parameters or change it; so the functions may have some optional fields. I tied to use the function missing(), but it will work properly only if the optional field is decleared at last in the function. Can you give me some suggestion an some reference? thank you. Claudio -- Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom http://click.libero.it/infostrada __ 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.
Re: [R] optional fields in function declarations
Can you provide an simple example of what you want the function to do? Generally, I set some value in the default. raise - function(x, power=1){ return( x^power ) } raise(5) [1] 5 raise(5,3) [1] 125 Or you can do the same but in a slightly unclear manner. raise - function(x, power){ if(missing(power)) power - 1 return( x^power ) } I prefer the former. Regards, Adai [EMAIL PROTECTED] wrote: Dear R users, I need to create a set of function to solve some tasks. I want to leave the operator to decide whether uses default parameters or change it; so the functions may have some optional fields. I tied to use the function missing(), but it will work properly only if the optional field is decleared at last in the function. Can you give me some suggestion an some reference? thank you. Claudio -- Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom http://click.libero.it/infostrada __ 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. __ 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.