s-news
[Top] [All Lists]

Re: Assignment within a function

To: "Kim Elmore" <Kim.Elmore@noaa.gov>, "S-News" <s-news@wubios.wustl.edu>
Subject: Re: Assignment within a function
From: "Barker, Chris" <Chris.Barker@cvt.com>
Date: Tue, 11 Nov 2008 14:52:45 -0800
In-reply-to: <491A066F.4000403@noaa.gov>
Thread-index: AclETIOaZgoQaAIZT2atc2DwciC3cQAA4xHg
Thread-topic: [S] Assignment within a function

It would be handy to see the function. I suspect the answer will require
that you use the "assign" statement.
 

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Kim Elmore
Sent: Tuesday, November 11, 2008 2:26
To: S-News
Subject: [S] Assignment within a function

I need to calculate he silhouette coefficient for a cluster object after

passing it through cutree(), which essentially returns a vector. I've 
written a function to do this, to which I pass a distance object (such 
as results from daisy() or dist()) and the output from cutree(). All 
works normally as a script, but when I make it into a function,  called 
silcoeff.fun(), I keep getting the following error:

Problem in silcoeff.fun(euclidean.no55.dis, cluster..: object "a" must 
be assigned locally before replacement
Use traceback() to see the call stack

When I look at traceback(), I see:

5: eval(action, sys.parent())
4: doErrorAction("Problem in silcoeff.fun(euclidean.no55.dis, cluster..:

object \"a\" must be assigned locally before replacement",
3: silcoeff.fun(euclidean.no55.dis, clusters.samp)
2: eval(expression(silcoeff.fun(euclidean.no55.dis, clusters.samp)))
1:
Message: Problem in silcoeff.fun(euclidean.no55.dis, cluster..: object 
"a" must be assigned locally before replacement

I'm not sure what object "a" is nor do I understand why I get this. I've

tried passing the distance object to the function as a matrix (I 
otherwise convert it to a matrix internally), and I've tried passing the

results of cutree to the function as a regular vector all to no avail. 
If I hard wire the dissimilarity and cutree input internally into the 
function, all is well, but when I try to pass these in, I get this
error.

Would someone please clue me into what I'm doing wrong?

Kim Elmore

-- 
Kim Elmore, Ph.D. (PP SEL/MEL/Glider, N5OP, 2nd Class Radiotelegraph,
GROL)
"All weather is divided into three parts: Yes, No and Maybe. The
greatest of these is maybe." -- The original Latin appears to be
garbled.

--------------------------------------------------------------------
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


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