[R] Odp: Object Browser

Douglas Bates bates at stat.wisc.edu
Tue Sep 28 14:07:40 CEST 2010


On Mon, Sep 27, 2010 at 3:04 AM, Petr PIKAL <petr.pikal at precheza.cz> wrote:
> Hi
> I noticed that nobody answered your question yet so here is my try.
>
> If you want to see what objects are in your environment you can use ls()
> but its output is only names of objects. Here is a function I use a long
> time for checking what objects are there, their type, size and possibly
> rows columns. You can modify it to give you some more info but usually it
> is not needed.
>
> Regards
> Petr
>
> ls.objects <- function (pos = 1, pattern, order.by)
> {
>    napply <- function(names, fn) sapply(names, function(x) fn(get(x,
>        pos = pos)))
>    names <- ls(pos = pos, pattern = pattern)
>    obj.class <- napply(names, function(x) as.character(class(x))[1])
>    obj.mode <- napply(names, mode)
>    obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
>    obj.size <- napply(names, object.size)
>    obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2]))
>    vec <- is.na(obj.dim)[, 1] & (obj.type != "function")
>    obj.dim[vec, 1] <- napply(names, length)[vec]
>    out <- data.frame(obj.type, obj.size, obj.dim)
>    names(out) <- c("Type", "Size", "Rows", "Columns")
>    if (!missing(order.by))
>        out <- out[order(out[[order.by]]), ]
>    out
> }

An alternative for the command line interface is

ls.str()

which combines ls() and a very brief version of str() as applied to
each of the objects.



More information about the R-help mailing list