[R] R function calling. Do I understand this right?
Paul E Johnson
pauljohn at ukans.edu
Mon Aug 28 15:31:51 CEST 2000
I need to write a nonhierarchical clustering routine and I'm studying
the way hclust (in the mva library) is built in R to see how things are
done and what I can modify. I ran f2c on the hclust.f file (so I could
read it in a language I know!) and there is one thing I don't quite
understand about the way it gets called and the way it returns values.
That Fortran function gets called in hclust.R, like this:
hclust <- function(d, method="complete")
{
<snip>
n <- attr(d, "Size")
if(is.null(n))
stop("invalid dissimilarities")
labels <- attr(d, "Labels")
len <- n*(n-1)/2
hcl <- .Fortran("hclust",
n = as.integer(n),
len = as.integer(len),
method = as.integer(method),
ia = integer(n),
ib = integer(n),
crit = double(n),
membr = double(n),
nn = integer(n),
disnn = double(n),
flag = logical(n),
diss = as.double(d), PACKAGE="mva")
<snip>
In this call, the "actual data" input is an integer "n", an integer
"len", an integer "method", and "diss", which is the vector obtained by
coercing bottom left part of a dissimiliarty matrix into a vector of
doubles.
So, I believe that means d is like this
x x x
1.1 x x
3.3 4.4 x
And diss is {1.1,3.3,4.4}
Now here is the qustion. All of the other variables listed as input,
ia,ib, crit,membr,nn,disnn, and flag, are just empty vectors being
passed through to be used inside the hclust function. Right? And the
changes made in those vectors inside the Fortran function are permanent,
so the other functions in the hclust.R file can use those values? (like
passing in a pointer in C?)
--
Paul E. Johnson email: pauljohn at ukans.edu
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list