How to control inheritance when dynamically extending Reference Classes
在WebCrawler/WebCraper设置中,我希望动态扩展我的基本引用类
有个办法,唯一的问题是我的类
你知道我怎样才能避免丢失那些重要的信息吗?
代码示例1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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" |
了解马丁所说的(见上面的评论):R 2.14.0修正了我上面描述的内容。