[S] Upgrade to my ls() function (Win9x flavor) [Part 1 of 2]

John Wallace (jrw@fish.washington.edu)
Tue, 27 Oct 1998 02:19:34 -0800 (PST)


Having been stymied by find() not having the ability to use wild
characters, I have upgraded my old ls() function
(www.fish.washington.edu/people/jrw/Splus/ls.txt) to search all, or any
subset of, the search list. Now the argument for search list position can
be a vector, not just a single number. I have also added an 'all'
argument which is equivalent to using the vector <1:length(seach())> for
the search list position argument.

Examples:

> ls(paste, all=T) # Note, the printout with all=T is a summary of the
# non-empty output. The complete output is invisibly
# returned.

[[5]]:
[1] "paste.fun.frame" "unpaste"

[[7]]:
[1] "paste"

[[13]]:
[1] "paste.command" "paste.value"

> ls(paste, c(5,7), long=T) # Here the printout is exactly what is
# returned invisibly. Note the list numbers
# are no longer the search list position
# numbers.

[[1]]:
data.class storage.mode extent object.size
paste.fun.frame function function 3 829
unpaste function function 7 11192
dataset.date
paste.fun.frame 206.02.05 22:28206.02.05 22:28\006
unpaste 206.02.05 22:28\006

[[2]]:
data.class storage.mode extent object.size
paste function function 4 633
dataset.date
paste 206.02.05 22:28\006

-------------------

My local functions are in position three on the search list, so:

> ls(ls, all=T, wild=F, long=T) # Leaving wild=T would have given all file
# objects that contained the 'ls' string
# ( "*ls*" ), not what I wanted.

[[1]]:
data.class storage.mode extent object.size dataset.date
ls function function 7 11108 98.10.23 17:11

[[3]]:
data.class storage.mode extent object.size dataset.date
ls function function 6 4298 95.08.17 10:46

[[7]]:
data.class storage.mode extent object.size dataset.date
ls function function 3 727 206.02.05 22:28\006

This shows that I need to replace my old ls() function (1995) with the
new one in the current working directory (1998). The ls() that comes
with Splus is seen to be in position seven.

----------------

Find all objects that start with 'un':

ls("un*", all=T, wild=F) # Win9x syntax

---------------------

With long=T and no pattern given, I have changed the mode to "any"
and sorted the result by "data.class":

ls(long=T)

ls(, 1:2, long=T)

---------------------

ls()

All the basic stuff still works. See
"www.fish.washington.edu/people/jrw/Splus/ls.txt" for more examples. That
file also contains the old ls() for Unix. Is there a desire for the above
in Unix?

-John

------------------------------

ls <- function(pattern = "[!.]*", pos = 1, all = F, wild.auto = T,
long = F, mode = "any")
{
#
# DATE WRITTEN: February 1995 LAST REVISED: 27 October 1998
# AUTHOR: John R. Wallace (jrw@fish.washington.edu)
#
if(all) pos <- 1:length(search())
if(!missing(pattern)) {
if(!is.character(substitute(pattern, frame =
sys.nframe())))
pattern <- deparse(substitute(pattern, frame
= sys.nframe()))
if(wild.auto)
pattern <- paste("*", pattern, "*", sep = "")
if(long)
out <- lapply(as.list(pos), function(a.pos,
pattern)
{
objects.summary(objects(a.pos, pat =
pattern), where = a.pos)
}
, pattern = pattern)
else out <- lapply(as.list(pos), objects, pat =
pattern)
}
else {
if(long)
out <- lapply(as.list(pos), function(a.pos,
mode)
{
obj.sum <- objects.summary(where =
a.pos, mode = mode)
obj.sum[order(obj.sum[, 1]), ]
}
, mode = mode)
else out <- lapply(as.list(pos), objects, pat =
pattern)
}
if(length(out) == 1 & long == F) {
out <- unlist(out)
print(out, q = F)
}
else {
xlen <- length(out)
this <- paste("[[", 1:xlen, "]]", sep = "")
for(i in 1:xlen) {
if(length(out[[i]]) > 0) {
if(is.data.frame(out[[i]]) == T) {
if(dim(out[[i]])[1] > 0) {
cat(this[i], ":\n", sep = "")
print(out[[i]], prefix = this[i],
q = F)
cat("\n")
}
}
else {
cat(this[i], ":\n", sep = "")
print(out[[i]], prefix = this[i], q
= F)
cat("\n")
}
}
}
}
invisible(out)
}

____________________

-- 
John Wallace
University of Washington                    ^    ^    ^
Fisheries Research Institute               / \  / \  / \   ^
Box 357980                                 / \  / \   |   / \
Seattle, WA 98195-7980                      |    |  o__~  / \
PHONE   (206) 543-1513                  @ @         /\/\   |
FAX     (206) 685-7471                   ~    
E-MAIL        jw@u.washington.edu              o
WWW      http://www.fish.washington.edu/people/jrw/Wallace.html 
                                                o  _///_ //
                                                <`)=  _<<
                                                    \\\  \\

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news