[R] Hook into Coercion Framework for data.frame

From: Von Der Hirschheydt, Juergen <juergen.vonderhirschheydt_at_credit-suisse.com>
Date: Tue, 26 Apr 2011 12:20:11 -0400


I am looking into a way to hook into the R coercion framework to allow me to convert table-like data stored within a COM object into a data.frame.

Some of our COM objects have their own table-like data storage, and from R's point of view it's an object (EXTPTRSXP) decoarated with a sepcial symbol so we can easily identify it.

	COM_Table <- a_method_that_creates_the_object()

> "QS.IpdgRelation"

In addition, we have a method that transforms this object into a data.frame:

        relation.to.data.frame <- function(obj) { ... }

A user can easily transform the above object into a data.frame by calling:

        myDataFrame <- relation.to.data.frame(COM_Table)

That all works nice and well, but we'd like to take it a step further and be able to call

	data.frame(COM_Table)		and/or

To achieve the same coercion. I've tried to hook into the coercion by using setAs :

	setOldClass ( "QS.IpdgRelation" )
	setAs ( "QS.IpdgRelation", "data.frame", function(from)
relation.to.data.frame(from) )

Which allows me to do

        as ( COM_Table, "data.frame" )

But I can't seem to get the last step to hook this coercion into the data.frame() or as.data.frame() call. Is there a way to achieve this, or am I chasing a red hering here ?

Any help appreciated,
Thanks a lot,


Please access the attached hyperlink for an important el...{{dropped:4}}

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 26 Apr 2011 - 16:57:28 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 Tue 26 Apr 2011 - 20:30:33 GMT.

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

list of date sections of archive