s-news
[Top] [All Lists]

Re: indexing feature (WAS indexing within a list using Splus

To: Bill.Venables@CMIS.CSIRO.AU
Subject: Re: indexing feature (WAS indexing within a list using Splus
From: Patrick Burns <pburns@pburns.seanet.com>
Date: Mon, 28 Oct 2002 12:46:58 +0000
Cc: ripley@stats.ox.ac.uk, Nick.Ellis@csiro.au, s-news@wubios.wustl.edu
References: <E09E527B56BE2D438A3D6A246DDD27A91655D7@Roper-CV.qld.cmis.csiro.au>
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20011126 Netscape6/6.2.1
Here is a specific example of what nerdy ole' Bill is talking about.

When making plots for publications, I like to write functions that create
the plots.  This means that months or years later there is no mucking about
trying to find how precisely that plot was made -- the data are stored inside
the function along with the plot commands.

The first step is to create a template function:

P.template <- function(file="xxx.eps")
{
        x <- 234
        if(length(file)) {
                # set up hardcopy plotting commands
        } else {
                # set up plotting to a window
        }
        plot(x)
}

Then create a specific instance:

P.description <- P.template

Then  specialize the instance:

P.description[[c(2,1,2)]] # make sure I have the right spot, should be 234
P.description[[c(2,1,2)]] <- the.real.x.object
P.description(NULL)  # look to see how well it works
P.description() # creates the file, the name in the function should be edited


In R, functions are not visibly lists like this (as well as R not having this form
of subscripting).  The same thing can be done in R of course (it is still S after
all), but not as neatly to my knowledge.

Patrick Burns
pburns@pburns.seanet.com

http://www.seanet.com/~pburns/Spoetry
http://www.i-way.co.uk/~pat/Spoetry


Bill.Venables@CMIS.CSIRO.AU wrote:
Just a minor footnote to Brian's reply below.  The only place where this
kind of indexing does seem to be useful is in dealing with language objects.
lists of lists of lists ... are not all that useful, or usual, but in
language elements expressions of calls of calls of .... are the norm.

Dealing with language objects does indeed take a 'certain type' of mindset -
the kind that revels in programming puzzles and challenges. Nerds like me,
in other words...:-)

Bill Venables.

-----Original Message-----
From: ripley@stats.ox.ac.uk [mailto:ripley@stats.ox.ac.uk]
Sent: Monday, October 28, 2002 5:45 PM
To: Nick.Ellis@csiro.au
Cc: s-news@wubios.wustl.edu
Subject: Re: [S] indexing feature (WAS indexing within a list using
Splus


I think that is cart-before-horse. It is not implemented in R, and there
was a request (nay, a bug report, PR#1558, by one of your colleagues) on
this. It just does not occur in any of the commonly-used S library
sections which have been ported to R.

I surmised at that time that people have not found it useful. I never
have. It must take a certain type of problem (or mindset) to work with
lists of lists of lists.

Brian

On Mon, 28 Oct 2002 Nick.Ellis@csiro.au wrote:

I got one reply on this indexing feature from Bill Venables. He pointed
out
that this form of indexing does not occur in R. That may explain why it is
rarely used, as one would try to avoid incompatibilities between the two
flavours of S.

Splus> list(list(list(1)))[[c(1,1,1)]]
[1] 1

R> list(list(list(1)))[[c(1,1,1)]]
Error: attempt to select more than one element

Nick Ellis
CSIRO Marine Research mailto:Nick.Ellis@csiro.au
PO Box 120 ph +61 (07) 3826 7260
Cleveland QLD 4163 fax +61 (07) 3826 7222
Australia http://www.marine.csiro.au

-----Original Message-----
From: Nick.Ellis@csiro.au [mailto:Nick.Ellis@csiro.au]
Sent: Thursday, October 24, 2002 10:49 AM
To: s.su@qut.edu.au
Cc: s-news@lists.biostat.wustl.edu
Subject: Re: [S] indexing within a list using Splus 2000 and Splus 6

For instance
A[[c(1,2,3)]] is the same
as A[[1]][[2]][[3]].

To the s-news community:
I don't remember anyone using this form of indexing on
s-news. I wonder if
anyone routinely uses this kind of indexing, and would like
to share any
tricks? The feature is not described under help("[["); you
have to go to the
Programmers' Guide, Chapter 4, section "Subscripting Li sts".


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