[Rd] RODBC and utils:object.size
Leif Kirschenbaum
leif at reflectivity.com
Tue Sep 27 20:37:27 CEST 2005
I would like to note that utils::object.size fails on RODBC connection objects.
> DB<-RODBC::odbcConnect("internal")
> utils::object.size(DB)
Error in utils::object.size(DB) : object.size: unknown type 22
>
I took a brief look at do_objectsize in the source code, and could not figure out how it dealt with new classes of objects. i.e. if someone defines a new class (such as "RODBC") are they supposed to define a size method for the class?
My current workaround for listing object sizes is to drop RODBC objects from Petr Pikal's original ls.objects() function:
ls.objects<-function (pos = 1, order.by,...)
{
napply <- function(names, fn) sapply(names, function(x) fn(get(x,pos=pos)))
names <- ls(pos = pos,...)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.drop <- match("RODBC",obj.class)
obj.class <- obj.class[-obj.drop]
names <- names[-obj.drop]
obj.mode <- napply(names, mode)
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
obj.size <- napply(names, object.size)
obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2]))
vec <- is.na(obj.dim)[, 1] & (obj.type != "function")
obj.dim[vec, 1] <- napply(names, length)[vec]
out <- data.frame(obj.type, obj.size, obj.dim)
names(out) <- c("Type", "Size", "Rows", "Columns")
if (!missing(order.by)) out <- out[order(out[[order.by]]), ]
out
}
Leif S. Kirschenbaum, Ph.D.
Senior Yield Engineer
Reflectivity, Inc.
More information about the R-devel
mailing list