s-news
[Top] [All Lists]

Re: SUMMARY: S-PLUS top tips

To: Henrik Aalborg Nielsen <immhan@student.dtu.dk>
Subject: Re: SUMMARY: S-PLUS top tips
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Thu, 26 Jul 2001 08:59:13 +0100 (BST)
Cc: <s-news@wubios.wustl.edu>
In-reply-to: <Pine.GSO.4.21.0107260922240.11209-100000@newton.gbar.dtu.dk>
On Thu, 26 Jul 2001, Henrik Aalborg Nielsen wrote:

> I'd say that the problem with functions c, q, s, t, C, D, and I is not
> that big at all:  If you make a non-function object with one of these
> names the only thing that does not work is that the function is not
> printed when it's name is typed at the prompth.  If you make a function
> which is allready there you get a warning... Or am I missing something
> here?

Yes. You only get a warning at the top level, not if you do this inside a
function.

test <- function()
{
  c <- rnorm(1)
  print(c(c, 3))
  c <- function(x) sum(x)/length(x)
  print(c(rnorm(100)))
}

> test()
[1] 1.199672 3.000000
[1] 0.05294651
[1] 0.05294651

... no warning.

Also, you can mask a function in a library section, and you will get no
warning unless the library section is currently attached.

However, I agree that this can be overplayed.  Back in the days of 3.x
it was serious.  Then S-PLUS started to check the mode and so only
functions could override functions, and in 5.x/6.x you get a warning
(which you can turn off).  But for the sake of code clarity, don't
redefine standard objects (and also to avoid a red face when you post a
mysterious error to S-news!).

> Example:
>
> > version
> Version 6.0 Release 1 for Sun SPARC, SunOS 5.6 : 2000
> > c <- rnorm(1)
> > c(c, 3)
> [1] 0.008629243 3.000000000
> > # OK
> > c <- function(x) sum(x)/length(x)
> Warning messages:
>   Conflicting definitions of "c" on databases "/home2/han/MySwork" and
> "splus"
> > c(rnorm(100))
> [1] 0.09876186
> > remove("c")
>
> /Henrik
>
> --------------------------------------------------------------------------
>    Henrik Aalborg Nielsen
>    Informatics and Mathematical Modelling
>    Section for Statistics, Time Series Group
>    Technical University of Denmark
>    Richard Petersens Plads, Build.321,
>    DK-2800 Kgs. Lyngby, Denmark.
>    Phone:  +45 4525 3418
>    Fax.:   +45 4588 2673
>    E-mail: han@imm.dtu.dk
>    URL:    http://www.imm.dtu.dk/~han
> --------------------------------------------------------------------------
>
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>