[R] R function calling. Do I understand this right?

Yves Gauvreau cyg at sympatico.ca
Tue Aug 29 12:40:12 CEST 2000


Here is what I get on my NT box under english locale or french. It seems I
have no problem.

> polut <- data.frame(Mortalité=c(82,97,76), Densité=c(600,960,570),
Pollution=c(110,140,90))
> attach(polut)
> summary(Mortalité)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   76.0    79.0    82.0    85.0    89.5    97.0
> summary(Pollution)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   90.0   100.0   110.0   113.3   125.0   140.0
> version
         _
platform Windows
arch     x86
os       Win32
system   x86, Win32
status
major    1
minor    1.0
year     2000
month    June
day      15
language R


----- Original Message -----
From: "Prof Brian D Ripley" <ripley at stats.ox.ac.uk>
To: "Paul E Johnson" <pauljohn at ukans.edu>
Cc: "R mailing list" <r-help at stat.math.ethz.ch>
Sent: Tuesday, August 29, 2000 2:47 AM
Subject: Re: [R] R function calling. Do I understand this right?


> On Mon, 28 Aug 2000, Paul E Johnson wrote:
>
> > 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?)
>
> No.  Copies of variables are made on entry and on exit. Thus the .C
> call returns a list of vectors with the names given.  You cannot
> alter the versions in the function, but you have to use explicitly
> the components of the returned result.  It's normal only to name
> components you are going to use subsequently, but some people
> name them all as an aide-memoire.
>
> (I am ignoring DUP=TRUE in .C in this dicussion.)
>
> If you are going to write in C you might want to start with .Call these
> days.
>
> --
> Brian D. Ripley,                  ripley at 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
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> 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
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

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