Interesting, but it seems too complex. In my opinion, just listing functions or non-functions meets my need. Anyway, thanks.
Daehyok Shin (Peter) > -----Original Message----- > From: S?en Merser [mailto:[EMAIL PROTECTED] > Sent: Sunday, June 20, 2004 AM 10:51 > To: Shin > Subject: Re: [R] A way to list only variables or functions? > > > hi > forgot who actualy wrote this code but it works nicely > use: > ls.objects(type='function') > > regards soren > > ls.objects<-function (pos = 1, pattern, mode = "any", type = "any"){ > Object.Name <- ls(pos = pos, envir = as.environment(pos), pattern = > pattern) > Object.Mode <- rep("",length(Object.Name)) > Object.Type <- rep("",length(Object.Name)) > Variables <- rep("-",length(Object.Name)) > Observations <- rep("-",length(Object.Name)) > for (i in 1:length(Object.Name)){ > Object.Mode[[i]] <- mode(get(Object.Name[[i]])) > if(is.list(get(Object.Name[[i]]))){ > if(is.null(class(get(Object.Name[[i]])))) > Object.Type[[i]] <- c("unknown") > else { > Object.Attrib <- attributes(get(Object.Name[[i]])) > if(length(Object.Attrib$class) == 1) { > Object.Type[[i]] <- Object.Attrib$class > if(Object.Type[[i]]=="data.frame"){ > Variables[[i]] <- as.character(length(Object.Attrib$names)) > Observations[[i]] <- as.character(length(Object.Attrib$row.names)) > } > } > else { > if("data.frame" %in% Object.Attrib$class){ > Object.Type[[i]] <- "data.frame" > Variables[[i]] <- as.character(length(Object.Attrib$names)) > Observations[[i]] <- as.character(length(Object.Attrib$row.names)) > } > else { > if("aov" %in% Object.Attrib$class) Object.Type[[i]] <- "aov" > } > } > } > } > if(is.matrix(get(Object.Name[[i]]))){ > Object.Attrib <- dim(get(Object.Name[[i]])) > Object.Type[[i]] <- c("matrix") > Variables[[i]] <- as.character(Object.Attrib[2]) > Observations[[i]] <- as.character(Object.Attrib[1]) > } > if(is.vector(get(Object.Name[[i]])) && (Object.Mode[[i]]=="character" || > Object.Mode[[i]]=="numeric")){ > Object.Type[[i]] <- c("vector") > Variables[[i]] <- c("1") > Observations[[i]] <- as.character(length(get(Object.Name[[i]]))) > } > if(is.factor(get(Object.Name[[i]]))){ > Object.Type[[i]] <- c("factor") > Variables[[i]] <- c("1") > Observations[[i]] <- as.character(length(get(Object.Name[[i]]))) > } > if(is.function(get(Object.Name[[i]]))) Object.Type[[i]] <- c("function") > } > objList <- > data.frame(Object.Name,Object.Mode,Object.Type,Observations,Variables) > if(mode != "any") objList <- objList[objList[["Object.Mode"]] > == mode,] > if(type != "any") objList <- objList[objList[["Object.Type"]] > == type,] > return(objList) > } > ----- Original Message ----- > From: "Shin" <[EMAIL PROTECTED]> > To: "R Help" <[EMAIL PROTECTED]> > Sent: Sunday, June 20, 2004 4:59 AM > Subject: [R] A way to list only variables or functions? > > > > I am curious if there is any way to list only variables or functions in > > current environment, rather than listing all objects? Thanks. > > > > -- > > Daehyok Shin (Peter) > > Geography Department > > Univ. of North Carolina-Chapel Hill > > > > ______________________________________________ > > [EMAIL PROTECTED] mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > > ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
