[R] Re RGui and object browser
Petr Pikal
petr.pikal at precheza.cz
Fri Jul 19 09:19:30 CEST 2002
Hallo Dan
I used your code for ls.objects and it is very usefull. I corrected some typo and it
worked well untill now.
I observed Error due to class evaluation in lists created by aov fit as the fitted
object from aov has two classes (aov and lm)
So I made a little change which seems to work.
Here it is:
# Posted by Dan Putler At 2002-07-15 16:13
# As part of the obveRsive GUI project, we've written a function with much of
# the functionality that Patrick Connolly was suggesting (which is a bit more
# compact than the output from ls.str()). Alas, no date capabilities. The
# function is call ls.objects(), and example output appears below:
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]]))
# this is the change which anable to get Correct object type with aov fits.
Object.Type[[i]] <- Object.Attrib$class[1]
if(Object.Type[[i]]=="data.frame"){
Variables[[i]] <- as.character(length(Object.Attrib$names))
Observations[[i]] <- as.character(length(Object.Attrib$row.names))
}
}
}
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)
}
Best regardsPetr Pikal
petr.pikal at precheza.cz
p.pik at volny.cz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list