11ll <- function (pos = 1 , unit = " KB" , digits = 0 , dim = FALSE , sort = FALSE , class = NULL ,
2- invert = FALSE , standard = " SI " , ... )
2+ invert = FALSE , ... )
33{
44 get.object.class <- function (object.name , pos )
55 {
66 object <- get(object.name , pos = pos )
7- class(object )[1 ]
7+ class <- class(object )[1 ]
8+ return (class )
89 }
910
1011 get.object.dim <- function (object.name , pos )
@@ -16,26 +17,26 @@ ll <- function(pos=1, unit="KB", digits=0, dim=FALSE, sort=FALSE, class=NULL,
1617 dim <- paste(dim(object ), collapse = " x " )
1718 else
1819 dim <- length(object )
19- dim
20+ return ( dim )
2021 }
2122
2223 get.object.size <- function (object.name , pos )
2324 {
2425 object <- get(object.name , pos = pos )
2526 size <- try(unclass(object.size(object )), silent = TRUE )
26- if (class (size ) == " try-error" )
27+ if (inherits (size , " try-error" ) )
2728 size <- 0
28- size
29+ return ( size )
2930 }
3031
31- # # 1 Set original.rank
32+ # # 1 Set unit, denominator, original.rank
33+ unit <- match.arg(unit , c(" bytes" ," KB" ," MB" ))
34+ denominator <- switch (unit , " KB" = 1024 , " MB" = 1024 ^ 2 , 1 )
3235 original.rank <- NULL
3336
3437 # # 2 Detect what 'pos' is like, then get class, size, dim
3538 if (is.character(pos )) # pos is an environment name
3639 pos <- match(pos , search())
37- if (isS4(pos )) # pos is an S4 object
38- pos <- sapply(slotNames(pos ), slot , object = pos , simplify = FALSE )
3940 if (is.list(pos )) # pos is a list-like object
4041 {
4142 if (is.null(names(pos )))
@@ -62,27 +63,13 @@ ll <- function(pos=1, unit="KB", digits=0, dim=FALSE, sort=FALSE, class=NULL,
6263 }
6364 else
6465 {
65- class.vector <- sapply(ls(pos ,... ),
66- get.object.class ,
67- pos = pos )
68-
69- size.vector <- sapply(ls(pos ,... ),
70- get.object.size ,
71- pos = pos )
72-
73- row.names <- names(size.vector )
74-
75- size.vector <- humanReadable(size.vector ,
76- units = unit ,
77- standard = standard ,
78- digits = digits )
79-
66+ class.vector <- sapply(ls(pos ,... ), get.object.class , pos = pos )
67+ size.vector <- sapply(ls(pos ,... ), get.object.size , pos = pos )
68+ size.vector <- round(size.vector / denominator , digits )
8069 object.frame <- data.frame (class.vector = class.vector ,
8170 size.vector = size.vector ,
82- row.names = row.names )
83-
71+ row.names = names(size.vector ))
8472 names(object.frame ) <- c(" Class" , unit )
85-
8673 if (dim )
8774 object.frame <- cbind(object.frame ,
8875 Dim = sapply(ls(pos ,... ),get.object.dim ,pos = pos ))
@@ -101,5 +88,5 @@ ll <- function(pos=1, unit="KB", digits=0, dim=FALSE, sort=FALSE, class=NULL,
10188 object.frame <- object.frame [include ,]
10289 }
10390
104- object.frame
91+ return ( object.frame )
10592}
0 commit comments