From ggrothendieck at gmail.com  Sun Nov 19 21:57:53 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Sun, 19 Nov 2006 15:57:53 -0500
Subject: [Rd] good practice for values not provided
In-Reply-To: <20061119204631.GA16883@pu100877.student.princeton.edu>
References: <20061119204631.GA16883@pu100877.student.princeton.edu>
Message-ID: <971536df0611191257x512df829r1650a158e56c8454@mail.gmail.com>

One possibility is:

f <- function(a, b, x) if (missing(x)) a+b else a-b-x

although that does have the disadvantage that one cannot explicitly tell
it not to use x but rather its denoted by its absence.

On 11/19/06, Tamas K Papp <tpapp at princeton.edu> wrote:
> Hi,
>
> I am writing a collection of functions which I plan to share as a
> package later (when they are tested thoroughly), so I would like to do
> things "right" from the beginning...
>
> I encountered a minor question of style.  Consider a function
>
> f <- function(a,b,x=NULL) {
>  ## ...
> }
>
> if !is.null(x), f will use x to calculate the result, but if
> is.null(x), it will do something else not involving x at all (using
> any x would be meaningless here, so I can't use
> x=calcsomethingfrom(a,b)).
>
> What's the accepted way of indicating this in R with a default for x?
> x=FALSE? x=NA? x=NULL?
>
> Thanks,
>
> Tamas
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] good practice for values not provided
Gabor Grothendieck