[R] getAttrb - Solved

Nicholas Lewin-Koh kohnicho at comp.nus.edu.sg
Thu Sep 7 09:32:41 CEST 2000


Hi,

I think what I found confusing is the extsenion writers manual states

"What happens if we want to add an attribute that is not pre-dened? We
need to add a symbol for it via a call to install. Suppose for
illustration we
wanted to add an attribute "version" with value 3.0. We could use 

{ 
SEXP version; 
PROTECT(version = allocVector(REALSXP, 1)); 
REAL(version) = 3.0;
setAttrib(ans, install("version"), version); 
 UNPROTECT(1);
}                  

So I assumed install was to install the attribute name in the symbol table
but not to retrieve it. Maybe a little clarification there would help such
as "intall can also be used in getAttrib() to retrive an attribute
installed in the sybol table"

Thanks
Nicholas

On Thu, 7 Sep 2000, Prof

> On Thu, 7 Sep 2000, Nicholas Lewin-Koh wrote:
> 
> > Hi,
> > I changed 
> > INTEGER(getAttrib(shape,mkChar("nParts")))[0]
> > to
> > INTEGER(getAttrib(shape,mkString("nParts")))[0]
> > 
> > and now it works fine.
> 
> In `Writing R Extensions' you would have seen that the second argument of
> getAttrib (and setAttrib) is the name in the symbol table, and the way to
> get that is install("nParts"). (Towards the end of section 3.6.4.)  The
> first line of getAttrib is in fact
> 
>     if (isString(name)) name = install(CHAR(STRING_ELT(name, 0)));
> 
> which shows that mkString is immediately being undone.
> 
> These internals are not very extensively documented, but this call was.
> In other cases, look at the usage in the code of R itself (src/main/*.c)
> for clarification.
> 
> -- 
> 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list