Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Oct 24 10:33:14 CEST 2005
This is one of those undocumented things (AFAIK): LENGTH applies only to
'vectors'. So don't use t and definitely don't set it for others. The
macro expands to
#define LENGTH(x) (((VECSEXP) (x))->vecsxp.length)
What is a vector here? Something which gets actually allocated by
allocVector() AFAICS, that is an atomic or generic vector or an
expression. OTOH, an EXTPTRSXP is stored in a cons cell.
There is also a function length(), which is safer.
On Mon, 24 Oct 2005, TB wrote:
> I'm using R_MakeExternalPtr() to store handles to (COM) objects in a SEXP.
> The code basically is
> sexp = R_MakeExternalPtr(handle,R_NilValue,R_NilValue);
> After creating the sexp, LENGTH(sexp) returns some quite large integer
> value. It seems like an "unitialized" value.
> Can I safely assume, that an SEXP of type EXTPTRSXP can only contain a
> single pointer value
It stores a pointer plus other things including a tag.
> and never represent a vector (an array) of pointers? Or
> should I maybe explicitly add something like
> Best wishes from sunny Austria,
> Thomas Baier
> R-devel at r-project.org mailing list
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
More information about the R-devel