File: object_size.R

package info (click to toggle)
gdata 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: sh: 27; makefile: 15
file content (64 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
object_size <- function(...)
{
  structure(sapply(list(...), utils::object.size),
            class=c("object_sizes", "numeric"))
}

print.object_sizes <- function(x, quote=FALSE,
                               humanReadable=getOption("humanReadable"),
                               standard="IEC", units, digits=1, width=NULL,
                               sep=" ", justify = c("right", "left"), ...)
{
  print(format(x, humanReadable=humanReadable, standard=standard, units=units,
               digits=digits, width=width, sep=sep,
               justify=justify), quote=quote, ...)
  invisible(x)
}

format.object_sizes <- function(x, humanReadable=getOption("humanReadable"),
                                standard="IEC", units, digits=1, width=NULL,
                                sep=" ", justify = c("right", "left"), ...)
{
  if(!missing(units))
  {
    if (units=="bytes")
      paste(x, "bytes")
    else
      humanReadable(x, standard=standard, units=units, digits=digits,
                    width=width, sep=sep, justify=justify)
  }
  else if(is.null(humanReadable) || humanReadable==FALSE)
  {
    paste(x, "bytes")
  }
  else
  {
    humanReadable(x, standard=standard, units=units, digits=digits, width=width,
                  sep=sep, justify=justify)
  }
}

is.object_sizes <- function(x)
  inherits(x, what="object_sizes")

as.object_sizes <- function(x)
{
  if(!is.numeric(x) || any(x<0))
    stop("'x' must be a positive numeric vector")
  class(x) <- c("object_sizes", "numeric")
  x
}

c.object_sizes <- function(..., recursive=FALSE)
{
  x <- NextMethod()
  if(is.numeric(x)) class(x) <- c("object_sizes", "numeric")
  x
}

object.size <- function(...)
{
  .Deprecated(old="gdata::object.size",
              new="object_size() or utils::object.size()")
  object_size(...)
}