2012-03-19 35 views
9

在試圖回答this Question我碰到這在str()「str()」輸出中的「隱藏列表」是什麼意思?

## R reference 
rref <- bibentry(bibtype = "Manual", 
     title = "R: A Language and Environment for Statistical Computing", 
     author = person("R Development Core Team"), 
     organization = "R Foundation for Statistical Computing", 
     address = "Vienna, Austria", 
     year = 2010, 
     isbn = "3-900051-07-0", 
     url = "http://www.R-project.org/") 

> str(rref) 
Class 'bibentry' hidden list of 1 
$ :List of 7 
    ..$ title  : chr "R: A Language and Environment for Statistical Computing" 
    ..$ author  :Class 'person' hidden list of 1 
    .. ..$ :List of 5 
    .. .. ..$ given : chr "R Development Core Team" 
    .. .. ..$ family : NULL 
    .. .. ..$ role : NULL 
    .. .. ..$ email : NULL 
    .. .. ..$ comment: NULL 
    ..$ organization: chr "R Foundation for Statistical Computing" 
    ..$ address  : chr "Vienna, Austria" 
    ..$ year  : chr "2010" 
    ..$ isbn  : chr "3-900051-07-0" 
    ..$ url   : chr "http://www.R-project.org/" 
    ..- attr(*, "bibtype")= chr "Manual" 

尤其是輸出來了,我很不解此位:

> str(rref) 
Class 'bibentry' hidden list of 1 
$ :List of 7 

什麼是「hidden list」位指?這是什麼樣的對象?這只是str()的一些格式化輸出,當對象中只有一個組件時,它本身就是一個列表?如果是的話,如何強制str()顯示完整的結構?

回答

8

這看起來像是一個str的人造物。我的解釋是,如果對象不是pairlist,則在str的輸出中將打印hidden list這兩個字。

由於你的目的是bibtex類的,並且存在用於bibtex沒有str方法,所述方法utils:::str.default用於描述的結構。

str.default

冷凝提取物:

... 
if (is.list(object)) { 
    i.pl <- is.pairlist(object) 
... 
cat(if (i.pl) 
    "Dotted pair list" 
    else if (irregCl) 
    paste(pClass(cl), "hidden list") 
    else "List", " of ", le, "\n", sep = "") 
... 
} 

定義irregCl關鍵位是:

.... 
else { 
    if (irregCl <- has.class && identical(object[[1L]], 
     object)) { 
.... 

和解釋隱藏列表位 - 它隱藏了外列表中,如果對象具有類和objectobject[[1]]是相同的。正如您在Answer中顯示的鏈接所示,如果列表包含單個對象,則[[方法將返回相同的對象。

+1

輝煌...... – BrodieG 2015-05-07 12:31:18