[R] help with generalized list function in R

Andrew White andrew_white at hmsa.com
Wed May 12 23:15:46 CEST 2004


In S-plus I have depended upon a simple extended ls() function developed by John wallace called lsx()

Reason: lsx() allows me to search for object names in my local workspace matching an unquoted character string.
Since I forget all the function names or data object names I have added, I can quickly find any/all names matching any specified string.

BUT: the lsx() function when installed (successfully, no errors reported) in R does not work in R.  
Why ? Can it be fixed so it can work?

Code is below:
---------------------------
lsx<-function(pattern, pos = 1, wild = T, long = F, mode = "function")
{
	#   lsx = extended listing: pattern match on quoted string, incl wildcards
	#
	#   LS-eXtended (saved as ls3.s): list objects all or matching <pattern>
	#   DATE WRITTEN:  February 1995      LAST REVISED:   15 August 1995
	#   AUTHOR:  John R. Wallace (jw at u.washington.edu)
	#
	if(!missing(pattern)) {
		if(!is.character(substitute(pattern, frame = sys.nframe())))
			pattern <- deparse(substitute(pattern, frame = sys.nframe()))
		if(wild)
			pattern <- paste("*", pattern,"*", sep = "")
		if(!(substring(as.character(version)[1], 2, 4) == "WIN"))
			pattern <- pat2grep(pattern)
		if(long)
			print(out <- objects.summary(objects(pos, pat = pattern), where = pos))
		else print(out <- objects(pos, pat = pattern), q = F)
	}
	else {
		if(long)
			print(out <- objects.summary(where = pos, mode = mode))
		else {
			if(substring(as.character(version)[1], 2, 4) == "WIN") {
				pattern <- "[!.]*"
				print(out <- objects(pos, pat = pattern), q = F)
			}
			else {
				all <- objects(pos)
				print(out <- all[!match(all, objects(pos, pat = "^\\."),no = 0)], q = F)
			}
		}
	}
	invisible(out)
}

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

Andy White
Andrew N. White, Ph.D. - Manager Research Unit
Financial Reporting & Medical Economics Dept.
Hawaii Medical Service Association
- Blue Cross Blue Shield of Hawaii
An Independent Licensee of the Blue Cross and Blue Shield Association -
818 Keeaumoku Street, Honolulu, HI 96814
Ph. 808-948-5344 - Email: andrew_white at hmsa.com




More information about the R-help mailing list