【问题标题】:What does "hidden list" in the output of `str()` mean?`str()` 的输出中的“隐藏列表”是什么意思?
【发布时间】:2012-03-19 09:46:17
【问题描述】:

在尝试回答 this Question 时,我在 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() 显示完整结构?

【问题讨论】:

    标签: r


    【解决方案1】:

    这似乎是str 的人工制品。我的解释是,如果对象不是pairlist,则hidden list 的输出中会打印出str 的字样。

    由于你的对象属于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 中所示,如果列表包含单个 "bibentry" 对象,[[ 方法将返回相同的对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-01
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      相关资源
      最近更新 更多