[R] getAttrb from a complex object

Nicholas Lewin-Koh kohnicho at comp.nus.edu.sg
Thu Sep 7 04:30:23 CEST 2000


Hi, I am writing C code to manipulate some complex objects in R, an object
of type Shape looks like the following

$Pstart 
[1] 0
$Pstartattr(,"row.names") 
[1] "Ring" 
$verts
           [,1] [,2]
 [1,] -82.41209 30.57731
 [2,] -82.41615 30.61270
       :
       :
[48,] -82.22104 30.56708 

attr(,"shp.type")
[1] 5
attr(,"nVerts") 
[1] 49 
attr(,"nParts") 
[1] 1 
attr(,"bbox")
[1] -82.69581  30.56594 -82.13134  31.46918

and the relevant C code is 
#include <R.h> 
#include <Rinternals.h> 
#include "maptools.h" 

SEXP Centroid(SEXP shape)
  {
     int i, j, n;
     double ai, atmp = 0, xtmp = 0, ytmp = 0, area;
     SEXP cent;
     Rprintf("parts: %d \n",
	     INTEGER(getAttrib(shape,mkChar("nParts")))[0]);

However calling the function i get
.Call("Centroid",Fl.poly$Shapes[[2]])
128 parts 


but parts should be 1 !

Any ideas?

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



More information about the R-help mailing list