How to manage inheritance when dynamically expanding reference classes

In the webcrawler / webscraper setting, I want to dynamically extend the base class of the Reference URL in order to be able to write specific methods for the respective hosts / domains. To be clear, dynamically I mean something like "automatically generate class definitions when new domains are encountered (for example, class URL_something.com that inherit from the class URL )."

Works with processing, the only problem is that my WebPage class expects the value of the URL field to have a class of URL . It will accept objects from the URL_something.com class, since it inherits from the URL class, but then actually turns the object into an instance of the URL class. Therefore, I lose the information that this is really the class URL_something.com .

Do you have any idea how I can prevent the loss of this important information?

Code example

 setRefClass(Class="URL", fields=list(x="character")) setRefClass(Class="WebPage", fields=list(url="URL")) obj <- new("WebPage", url=new("URL", x="http://www.something.com/home/index.html")) obj$url # Method would recognize that there is no class 'URL_something.com' # yet and thus create it: setRefClass(Class="URL_something.com", contains="URL") # Another method would take care of mapping field values to # an instance of the new class: > url.obj <- new("URL_something.com", x="http://www.something.com/home/index.html") > inherits(url.obj, "URL") [1] TRUE > obj$url <- url.obj > class(obj$url) [1] "URL" # So I lose the information that it was actually of class "URL_something.com" 
+4
source share
1 answer

Picking up what Martin said (see comments above): R 2.14.0 corrects what I described above.

+1
source

All Articles