Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "hidden list" in the output of `str()` mean?

Tags:

r

In attempting to Answer this Question I came across this in the output of 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"

In particular, I'm puzzled by this bit:

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

What does the "hidden list" bit refer to? What kind of object is this? Is this just some formatting output from str() when there is only a single component in the object that is itself a list? If so how is there a way to force str() to show the full structure?

like image 211
Gavin Simpson Avatar asked Mar 19 '12 09:03

Gavin Simpson


1 Answers

This seems like an artefact of str. My interpretation is that the words hidden list are printed in the output of str if the obect is not a pairlist.

Since your object is of class bibtex, and there is no str method for bibtex, the method utils:::str.default is used to describe the structure.

Condensed extract from 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 = "")
...
}

The key bit that defines irregCl is:

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

and that explain the hidden list bit - it hides the outer list if the object has a class and object and object[[1]] are identical. As you showed in the Answer you linked to, the [[ method returns an identical object if the list contains a single "bibentry" object.

like image 61
Andrie Avatar answered Nov 15 '22 12:11

Andrie