首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >` `str()`输出中的“隐藏列表”是什么意思?

` `str()`输出中的“隐藏列表”是什么意思?
EN

Stack Overflow用户
提问于 2012-03-19 17:46:18
回答 1查看 1K关注 0票数 11

在尝试回答this Question时,我在str()的输出中遇到了以下内容

代码语言:javascript
复制
## 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"

特别是,我对这一点感到困惑:

代码语言:javascript
复制
> str(rref)
Class 'bibentry'  hidden list of 1
 $ :List of 7

"hidden list“位指的是什么?这是什么类型的物体?当对象中只有一个本身是列表的组件时,这仅仅是str()的一些格式化输出吗?如果是这样的话,如何强制str()显示完整的结构?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-19 18:08:30

这看起来像是str的杰作。我的解释是,如果对象不是pairlist,则在str的输出中打印单词hidden list

由于您的对象属于bibtex类,并且没有用于bibtexstr方法,因此使用utils:::str.default方法来描述该结构。

来自str.default的压缩摘录

代码语言:javascript
复制
...
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的密钥位是:

代码语言:javascript
复制
....
else {
     if (irregCl <- has.class && identical(object[[1L]], 
         object)) {
....

这就解释了隐藏列表位-如果对象有一个类并且objectobject[[1]]相同,它就会隐藏外部列表。正如您在链接到的Answer中所示,如果列表包含单个"bibentry"对象,则[[方法将返回一个相同的对象。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9767959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档