Skip to content
Back to formatted view

Raw Message

Message-ID: <p46qav82rg5gqrcgngr8amsp9c70hmfm75@4ax.com>
Date: 2003-04-28T12:15:08Z
From: Duncan Murdoch
Subject: sum(..., na.rm=TRUE) oddity
In-Reply-To: <3EAD1060.8010309@lancaster.ac.uk>

On Mon, 28 Apr 2003 12:28:32 +0100, Barry Rowlingson
<B.Rowlingson at lancaster.ac.uk> wrote:

>  Are you certain you typed 'na.rm'? I have occasionally typed 'rm.na' 
>instead, and something like that might explain things:
>
>
> > sum(1,1,na.rm=TRUE)
>[1] 2
>
> > sum(1,1,rm.na=TRUE)
>[1] 3

Is there ever any reason to name the summands?  I'd think it would be
reasonable to generate an error, or at least a warning, in a case
where any of the arguments to be summed are named.  For example 

sum <- function (..., na.rm = FALSE) {
  if (!is.null(names(list(...)))) 
      stop(paste('Named summands:',paste(names(list(...)),collapse='
')))
  .Internal(sum(..., na.rm = na.rm))
}

gives this:

> sum(1,1,rm.na=TRUE)
Error in sum(1, 1, rm.na = TRUE) : Named summands:   rm.na

Duncan Murdoch