[Rd] round() ignores missing arguments if it is used inside another function where some arguments are missing.

Joris Meys jorismeys at gmail.com
Fri Nov 18 16:43:05 CET 2011


I have stumbled across some behaviour in R that I really can't place,
and that makes coding a bit tricky. I know that I can work around it
when explicitly checking for missing arguments, but still...
I have two functions. I have a first function based on paste

    fun1 <- function(x,y){
      print(missing(y))
      paste(x,'X',sep=y)
    }

If I try this function without specifying `y`, I get the (expected)
error message:

    > fun1(letters[1:6])
    [1] TRUE
    Error in paste(x, "X", sep = y) :
      argument "y" is missing, with no default

The second one with round :
    fun2 <- function(x,y){      print(missing(y))      round(x,digits=y)    }
If I try this function without specifying `y`, it works unexpectedly
whereas it shouldn't :
    > fun2(100.1)    [1] TRUE    [1] 100
In my view, fun1 should definitely give the error message as well, as
it is not intended to have a default behaviour when y is missing.
Still, the round() function ignores the fact y is missing. Is this by
design, is there a check missing in round, or is something else going
on that I am overlooking?

Cheers
Joris
> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
[7] base

loaded via a namespace (and not attached):
[1] tools_2.14.0

-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-devel mailing list