Re: [R] more structure than 'str'?

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Sun, 16 Dec 2007 19:08:00 -0800

On Sun, 16 Dec 2007, Spencer Graves wrote:

> How can I see more of the structure than displayed by 'str'?

str is generic.

> methods(str)

[1] str.data.frame* str.default* str.dendrogram* str.logLik* str.POSIXt*

    Non-visible functions are asterisked
>

As you see there is a data.frame method that chooses not to report on the "row.names" attribute.

You can get the default behavior by removing the class attribute:

> str(unclass(tstDF))

List of 1
  $ a: num 1

HTH, Chuck

> Consider the following:
>
>
> tstDF <- data.frame(a=1, row.names='b')
> > str(tstDF)
> 'data.frame': 1 obs. of 1 variable:
> $ a: num 1
>
>
> The object 'tstDF' has row.names, but I have to suspect they are
> there -- AND know a function like 'row.names' or 'dimnames' -- to see
> them.
>
> I've found 'str' extremely valuable for understanding and
> explaining to others the internal structure of an R object. In many
> cases, it has helped me find fairly simple ways to do things with R
> objects that might have been much more difficult and perhaps infeasible
> without 'str' -- and without access to the right expert, who may not be
> available in the time I have to solve a particular problem.
>
> Thanks again to Martin Maechler, who wrote 'str', and to everyone
> else who has replied to questions from me over the years.
>
> Best Wishes,
> Spencer Graves
> p.s. 'methods(class="data.frame")' would help in this example.
> However, 'methods' won't always find all available and recommended
> extractor functions. For example, 'methods(class="lm")' was not able to
> find 'AIC' for me just now.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 17 Dec 2007 - 03:11:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Dec 2007 - 06:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.