[Rd] recursive data-structures in R - An S4 "node" Class

From: rt <taylor.russ_at_gmail.com>
Date: Sat, 23 Jan 2010 20:18:55 -0600


In an effort to learn S4 objects, I am trying to port some c based tree code to S4 object. My immediate goal is to use .Call() interface for calling my c code from R. My long term goal is to understand how to write c structs that follows S4 classes and not the other-way-around.

The c struct for the node is :
typedef struct node{
  int c;
  int n;
  inode **nodes; //length = n
} inode;

I am trying to define corresponding S4 class. The closest I could come was: setClassUnion("listOrNULL",members=c("list", "NULL")) setClass(Class = "Inode", representation(c = "numeric",n="numeric",nodes="listOrNULL"))

This does not work, as setting an element of the list of nodes in a node object overwrites the original object. I have read that there are dirty ways of writing code that gets around this issue. For example, using the assign() operator.
I am not even sure if it will work.

I would appreciate if someone suggest ways in which this problem is best approached.
Is it possible to have recursive data-structures within R ? What is the best way of writing an interface with pre-existing c code? What are the best practices for deveolping new code in c for such purposes?



        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 24 Jan 2010 - 02:22:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Jan 2010 - 21:40:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive