Re: [R] Optional variables in function?
jim holtman wrote: ?missing On 7/2/06, Jonathan Greenberg [EMAIL PROTECTED] wrote: I'm a bit new to writing R functions and I was wondering what the best practice for having optional variables in a function is, and how to test for optional and non-optional variables? e.g. if I have the following function: helpme - function(a,b,c) { } In this example, I want c to be an optional variable, but a and b to be required. How do I: 1) test to see if the user has inputted c 2) break out of the function of the user has NOT inputted a or b. if(missing(c)) stop(need c) or if(missing(c)) return() depending on your problem it might be better to provide sensible default values for a,b,c in the function definition helpme-function(a=A, b=B, c=C) {...} instead of enforcing that every argument is specified? joerg Thanks! --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Phone: 415-794-5043 AIM: jgrn3007 MSN: [EMAIL PROTECTED] __ 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 __ 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
Re: [R] Optional variables in function?
?missing On 7/2/06, Jonathan Greenberg [EMAIL PROTECTED] wrote: I'm a bit new to writing R functions and I was wondering what the best practice for having optional variables in a function is, and how to test for optional and non-optional variables? e.g. if I have the following function: helpme - function(a,b,c) { } In this example, I want c to be an optional variable, but a and b to be required. How do I: 1) test to see if the user has inputted c 2) break out of the function of the user has NOT inputted a or b. Thanks! --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Phone: 415-794-5043 AIM: jgrn3007 MSN: [EMAIL PROTECTED] __ 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 -- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[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
[R] Optional variables in function?
I'm a bit new to writing R functions and I was wondering what the best practice for having optional variables in a function is, and how to test for optional and non-optional variables? e.g. if I have the following function: helpme - function(a,b,c) { } In this example, I want c to be an optional variable, but a and b to be required. How do I: 1) test to see if the user has inputted c 2) break out of the function of the user has NOT inputted a or b. Thanks! --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Phone: 415-794-5043 AIM: jgrn3007 MSN: [EMAIL PROTECTED] __ 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