a nicer ls for R
April 29th, 2007
R already has a function called ls(), which simply lists the names of all objects in the current environment, and ls.str(), which does so with a lot more information. I wanted one that looks a little more similar to ls -l in a Unix environment, so here’s a start:
my.ls <- function(envir = as.environment(-1)) {
names <- .Internal(ls(envir, all.names=T))
for (item in names) {
l1 <- length(get(item))
l2 <- ""
if (!is.null(dim(get(item)))) {
l1 <- dim(get(item))[1]
l2 <- sprintf("%10d", dim(get(item))[2])
}
cat(sprintf("%-30s %-10s %-10s %10d %10sn",
item, class(get(item)), mode(get(item)), l1, l2))
}
}
Entry Filed under: programming, linux, R
Leave a Comment
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed