在尝试回答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()显示完整的结构?
发布于 2012-03-19 18:08:30
这看起来像是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)) {
....这就解释了隐藏列表位-如果对象有一个类并且object和object[[1]]相同,它就会隐藏外部列表。正如您在链接到的Answer中所示,如果列表包含单个"bibentry"对象,则[[方法将返回一个相同的对象。
https://stackoverflow.com/questions/9767959
复制相似问题