s-news
[Top] [All Lists]

[S] Thanks. Function scoping question

To: s-news@wubios.wustl.edu
Subject: [S] Thanks. Function scoping question
From: "Marc R. Feldesman" <feldesmanm@pdx.edu>
Date: Mon, 26 Apr 1999 08:58:46 -0700
Sender: owner-s-news@wubios.wustl.edu
Thanks to all (Dave Krantz, Andreas Krause, Song Qian, Todd Taylor, Mark
Bravington, Doug Bates, Bill Dunlap) who replied to my query concerning
function scoping rules in S, particularly concerning apply().  I had forgotten
about the (...) piece of apply.  Having the extra arguments available for
apply() certainly solves the problem I had with the trivial, demonstration
function I wrote for my email.  

While it solves that problem, the larger problem for me still remains.  Earlier
I posed the problem of trellising qqplots conditioned on a grouping variable. 
I can see an error related to apply() in *this* function too, but fixing that
error doesn't solve the problem I'm still struggling with.

S does not seem to have the C equivalent of a static variable, at least not
when using apply().  When using apply to "loop" through a set of variables,
there doesn't seem to be any way to get apply to "remember" the current (much
less previous) value of a vector's "name" attribute to use it as a ylabel on a
trellis panel.  

In the function (revised to use apply correctly):

"qqhowell" <- function(x, group)
{
        apply(x, 2, function(j, y)
        {       
                qqmath( ~ j | y, panel = function(xx, yy)               {#
stolen from built-in example of qqmath plot          panel.qqmathline(yy,
distribution = qnorm)              panel.qqmath(xx, yy)
                })
        }, group)
}

There does not seem to be any way to get a ylab argument for each panel to
assume (in turn) the vector names composing the original data.frame "x".  It
appears that each time apply() is "applied", the vector is incremented, but
this information isn't made "public" to the panel functions doing the work.   

Since no one has responded to my original posts, it appears that either my
problem still is not clear enough to respond to, or that this is a problem that
is not solveable using the particular paradigm I'm trying.  I haven't tried it
yet, but could this be a case where a for loop might be more appropriate than
apply()?

Dr. Marc R. Feldesman
email:  feldesmanm@pdx.edu
email:  feldesman@ibm.net
fax:    503-725-3905

"Math is hard.  Let's go to the mall"  Barbie

Powered by:  Monstrochoerus - the 300 MHz Pentium II
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>
  • [S] Thanks. Function scoping question, Marc R. Feldesman <=