[R] NULL or NA for missing function arguments?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Oct 16 14:58:46 CEST 2006


There is also a third way, namely use the missing function
in the code:

f <- function(x) if (missing(x)) print("missing") else print(x)
f()


On 10/16/06, Hans-Peter <gchappi at gmail.com> wrote:
> Hi,
>
> I am troubled by the use of NULL or NA to indicate
> missing/non-specified function arguments.
>
> In the R code that I have looked at, it seems that both forms are used
> (NULL seems to be used more often though). Sometimes both variants are
> in the same declaration, e.g.
>
> format.default <-
>    function(x, trim = FALSE, digits = NULL, nsmall = 0,
>             justify = c("left", "right", "centre", "none"),
>             width = NULL, na.encode = TRUE, scientific = NA,
>             big.mark = "", big.interval = 3,
>             small.mark = "", small.interval = 5, decimal.mark = ".",
>             zero.print = NULL, ...)
>
> Is there a right way? And if both forms are used, how do I know which
> one is right?
>
> Thanks a lot and best regards,
> Hans-Peter
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list