[R] Calling R function from within C code

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Jan 16 18:24:23 CET 2003


ripley at stats.ox.ac.uk writes:

> It's hard to know where to start from.  A pairlist is a linked list of R
> objects, a generic vector (of mode list) is an array of pointers to R
> objects.  They are just different (and I've simplified by ignoring 
> tags/names).  A paired list has sequential access, a generic vector random 
> access, but it is less expensive to append to / insert in a pairlist.

Or, think Lisp: in Lisp a list is written like

( A B C )

and the internal representation is in terms of the "head" A and the
"tail" ( B C ). All lists are represented as such pairs (single
element lists have a pointer to the value as head and NIL as the
tail).

For historical reasons, Lisp'ers refer to the head bit as CAR and the
tail as CDR. This has to do with the first implementations which were
on an IBM 704 machine which stored the two pointers in the CPU's
Address Register and the Decrement Register, so CAR is "Content of the
Address Register", etc. You'll also see CONS which constructs a list
given its CAR and a CDR and shorthand macros like CADDR which is
CAR(CDR(CDR(x))) (and will give you the "C" in ( A B C )

Notice that this representation is radically different from a vector
of mode "list". Pairlists are extremely flexible for things like
inserting and deleting elements in-place, but accessing the n-th
element requires counting from the head.

R, being a modified Scheme engine, used to have pairlists for its list
structure, but the sequential access became a performance problem
(esp. with ported S code). There are still a few places where
pairlists are visible at the user level if you know where to look...

> On Thu, 16 Jan 2003, Timur Elzhov wrote:
> 
> > On Thu, Jan 16, 2003 at 03:22:42PM +0000, ripley at stats.ox.ac.uk wrote:
> > 
> > > That way.  It's a pairlist of arguments.  As that manual says
> > Thank you, Mr. Ripley!
> > 
> > But, it was interesing for me for a long - what is a principal
> > difference between 'pairlist' and a "general" list?
> > Why to access pairlist elements I need to use the strange macro
> > like CAR(CDR(x)), and cannot do it by VECTOR_ELT(x, i) ?
> 
> 
> -- 
> 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 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list