2010-12-09 31 views
4

我從S4類定義中識別出一個來自較舊包的類時遇到了一些麻煩。我不斷收到錯誤從S4類定義中的包中識別出S3(?)類

Error in makePrototypeFromClassDef(properties, ClassDef, immediate, where) : 
    in making the prototype for class "Tsvmm" elements of the prototype failed to 
    match the corresponding slot class: dates (class "dates") 
In addition: Warning message: 
undefined slot classes in definition of "Tsvmm": dates(class "dates") 

重複的例子:

require(chron) 

setClass(
    Class="Tsvmm", 
    representation=representation(
     data = "data.frame", 
     dates = "dates" 
), 
    prototype=prototype(
     data = data.frame(), 
     dates = chron(0) 
) 
) 

當試圖class(chron(0)),答案是"dates" "times"。使用is.numeric(chron(0)),答案是TRUE。但是,當我將插槽日期類別設置爲"numeric"時,我收到了沒有警告消息的相同錯誤。

我有這種感覺,我忽略了一些明顯的東西,但是我在文檔中找不到它。任何人有任何指針? PS:我知道chron包至少是特有的,但我有充分的理由使用它。此外,其他軟件包可能會出現問題。將此視爲一般問題的示例。所以,請不要告訴我使用Date或POSIXt類。這是我現在使用的黑客技術。

+2

wowThatFunctionNameIsLong() – 2010-12-09 16:56:12

回答

6

看來你需要setOldClass使方法相信日期是一個真正的類。

+1

賓果!謝謝 – 2010-12-09 23:18:05

2

我有類似的問題,因爲Gtk2對象(例如,Gtk2 :: GtkBuilder)不是S4類,而我想在我自己的代碼中的一個這樣的對象的實例。我想我通過刪除prototype()事物並使用「initialize()」方法來解決這種情況。