Skip to content

getAttrb - Solved

4 messages · Nicholas Lewin-Koh, Brian Ripley

#
Hi,
I changed 
INTEGER(getAttrib(shape,mkChar("nParts")))[0]
to
INTEGER(getAttrib(shape,mkString("nParts")))[0]

and now it works fine.

Nicholas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 7 Sep 2000, Nicholas Lewin-Koh wrote:

            
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.
#
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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 7 Sep 2000, Nicholas Lewin-Koh wrote:

            
Alternatively, just read the very next sentence in that section:

`Using install when it is not needed is harmless and provides a
simple way to retrieve the symbol from the symbol table if it is already
installed.'

I don't think you will find anywhere that it says to use mkChar!