[R] don't print object attributes

Duncan Murdoch murdoch.duncan at gmail.com
Tue Aug 28 19:34:53 CEST 2012


On 28/08/2012 1:12 PM, Liviu Andronic wrote:
> Dear all
> Suppose the object below:
> > require(Hmisc)
> > require(plyr)
> > x <- dlply(iris, .(Species), describe)
>
> How can I print the object without displaying the attributes? I
> inspected ?print and ?print.default with no luck.

Assign a class to the object, and write a print method for it.

For example, this doesn't quite do what you want, but it's a start:

print.noattributes <- function(x, ...) {
    attributes(x) <- NULL
    print(x)
}

class(x) <- "noattributes"
x

It loses some attributes that you probably want to keep (e.g. the 
names), but otherwise works on your example.

Duncan Murdoch


> > x
> $setosa
> x[, "Sepal.Length"]
>        n missing  unique    Mean     .05     .10     .25     .50     .75
>       50       0      15   5.006    4.40    4.59    4.80    5.00    5.20
>      .90     .95
>     5.41    5.61
>
>            4.3 4.4 4.5 4.6 4.7 4.8 4.9  5 5.1 5.2 5.3 5.4 5.5 5.7 5.8
> Frequency   1   3   1   4   2   5   4  8   8   3   1   5   2   2   1
> %           2   6   2   8   4  10   8 16  16   6   2  10   4   4   2
>
> $versicolor
> x[, "Sepal.Length"]
>        n missing  unique    Mean     .05     .10     .25     .50     .75
>       50       0      21   5.936   5.045   5.380   5.600   5.900   6.300
>      .90     .95
>    6.700   6.755
>
> lowest : 4.9 5.0 5.1 5.2 5.4, highest: 6.6 6.7 6.8 6.9 7.0
>
> $virginica
> x[, "Sepal.Length"]
>        n missing  unique    Mean     .05     .10     .25     .50     .75
>       50       0      21   6.588   5.745   5.800   6.225   6.500   6.900
>      .90     .95
>    7.610   7.700
>
> lowest : 4.9 5.6 5.7 5.8 5.9, highest: 7.3 7.4 7.6 7.7 7.9
>
> attr(,"split_type")
> [1] "data.frame"
> attr(,"split_labels")
>       Species
> 1     setosa
> 2 versicolor
> 3  virginica
>
> Regards
> Liviu
>
>




More information about the R-help mailing list