Browse Source

Merge branch 'master' of github.com:hrbrmstr/ggalt

pull/6/head
Bob Rudis 8 years ago
parent
commit
634a1311c9
  1. 5
      NAMESPACE
  2. 4
      NEWS
  3. 82
      R/formatters.r
  4. 3
      README.Rmd
  5. 50
      man/byte_format.Rd

5
NAMESPACE

@ -6,14 +6,19 @@ S3method(grobWidth,absoluteGrob)
S3method(grobX,absoluteGrob)
S3method(grobY,absoluteGrob)
export(CoordProj)
export(Gb)
export(GeomBkde)
export(GeomBkde2d)
export(GeomStateface)
export(GeomXspline)
export(Kb)
export(Mb)
export(StatAsh)
export(StatBkde)
export(StatBkde2d)
export(StatXspline)
export(byte_format)
export(bytes)
export(coord_proj)
export(geom_bkde)
export(geom_bkde2d)

4
NEWS

@ -0,0 +1,4 @@
0.1.5
=====================
* Pokemon discrete color scales!
* `byte_format` (et al) scales (e.g. 10000 => 10 Kb)

82
R/formatters.r

@ -0,0 +1,82 @@
#' Bytes formatter: convert to byte measurement and display symbol.
#'
#' @return a function with three parameters, \code{x}, a numeric vector that
#' returns a character vector, \code{symbol} the byte symbol (e.g. "\code{Kb}")
#' desired and the measurement \code{units} (traditional \code{binary} or
#' \code{si} for ISI metric units).
#' @param x a numeric vector to format
#' @param symbol byte symbol to use. If "\code{auto}" the symbol used will be
#' determined by the maximum value of \code{x}. Valid symbols are
#' "\code{b}", "\code{K}", "\code{Mb}", "\code{Gb}", "\code{Tb}", "\code{Pb}",
#' "\code{Eb}", "\code{Zb}", and "\code{Yb}", along with their upper case
#' equivalents and "\code{iB}" equivalents.
#' @param units which unit base to use, "\code{binary}" (1024 base) or
#' "\code{si}" (1000 base) for ISI units.
#' @references Units of Information (Wikipedia) :
#' \url{http://en.wikipedia.org/wiki/Units_of_information}
#' @export
#' @examples
#' byte_format()(sample(3000000000, 10))
#' bytes(sample(3000000000, 10))
byte_format <- function(symbol="auto", units="binary") {
function(x) bytes(x, symbol, units)
}
#' @export
#' @rdname byte_format
Kb <- byte_format("Kb", "binary")
#' @export
#' @rdname byte_format
Mb <- byte_format("Mb", "binary")
#' @export
#' @rdname byte_format
Gb <- byte_format("Gb", "binary")
#' @export
#' @rdname byte_format
bytes <- function(x, symbol="auto", units=c("binary", "si")) {
symbol <- match.arg(symbol, c("auto",
"b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb",
"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB",
"KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"))
units <- match.arg(units, c("binary", "si"))
base <- switch(units, `binary`=1024, `si`=1000)
if (symbol == "auto") {
symbol <-
if (max(x) >= (base^5)) { "Pb" }
else if (max(x) >= (base^4)) { "Tb" }
else if (max(x) >= (base^3)) { "Gb" }
else if (max(x) >= (base^2)) { "Kb" }
else if (max(x) >= (base^1)) { "Mb" }
else { "b" }
}
switch(symbol,
"b" =, "B" = paste(x, "bytes"),
"Kb" =, "KB" = paste(round(x/(base^1), 1L), "Kb"),
"Mb" =, "MB" = paste(round(x/(base^2), 1L), "Mb"),
"Gb" =, "GB" = paste(round(x/(base^3), 1L), "Gb"),
"Tb" =, "TB" = paste(round(x/(base^4), 1L), "Tb"),
"Pb" =, "PB" = paste(round(x/(base^5), 1L), "Pb"),
"Eb" =, "EB" = paste(round(x/(base^6), 1L), "Eb"),
"Zb" =, "ZB" = paste(round(x/(base^7), 1L), "Zb"),
"Yb" =, "YB" = paste(round(x/(base^8), 1L), "Yb"),
"KiB" = paste(round(x/(base^1), 1L), "KiB"),
"MiB" = paste(round(x/(base^2), 1L), "MiB"),
"GiB" = paste(round(x/(base^3), 1L), "GiB"),
"TiB" = paste(round(x/(base^4), 1L), "TiB"),
"PiB" = paste(round(x/(base^5), 1L), "PiB"),
"EiB" = paste(round(x/(base^6), 1L), "EiB"),
"ZiB" = paste(round(x/(base^7), 1L), "ZiB"),
"YiB" = paste(round(x/(base^8), 1L), "YiB")
)
}

3
README.Rmd

@ -39,12 +39,13 @@ The following functions are implemented:
- `stat_ash` : Compute and display a univariate averaged shifted histogram (polynomial kernel) (uses `ash::ash1`/`ash::bin1`)
- `scale_color_pokemon` :
- `scale_fill_pokemon` : discrete pokemon scales (data taken from the hard work by the <http://www.pokegraphs.com/>)
- `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
### News
- Version 0.1.5.9000 - Pokemon discrete color scales!
- Version 0.1.2.9000 - Fixed bug with limits not working thx to @mstrimas
- Version 0.1.2.9000 - Fixed bug with limits not working in coord_proj thx to @mstrimas
- Version 0.1.1 - CRAN!
- Version 0.1.0.9000 - Tweaks for ggplot2 2.0 release
- Version 0.0.4.9000 - `stat_ash`

50
man/byte_format.Rd

@ -0,0 +1,50 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formatters.r
\name{byte_format}
\alias{Gb}
\alias{Kb}
\alias{Mb}
\alias{byte_format}
\alias{bytes}
\title{Bytes formatter: convert to byte measurement and display symbol.}
\usage{
byte_format(symbol = "auto", units = "binary")
Kb(x)
Mb(x)
Gb(x)
bytes(x, symbol = "auto", units = c("binary", "si"))
}
\arguments{
\item{symbol}{byte symbol to use. If "\code{auto}" the symbol used will be
determined by the maximum value of \code{x}. Valid symbols are
"\code{b}", "\code{K}", "\code{Mb}", "\code{Gb}", "\code{Tb}", "\code{Pb}",
"\code{Eb}", "\code{Zb}", and "\code{Yb}", along with their upper case
equivalents and "\code{iB}" equivalents.}
\item{units}{which unit base to use, "\code{binary}" (1024 base) or
"\code{si}" (1000 base) for ISI units.}
\item{x}{a numeric vector to format}
}
\value{
a function with three parameters, \code{x}, a numeric vector that
returns a character vector, \code{symbol} the byte symbol (e.g. "\code{Kb}")
desired and the measurement \code{units} (traditional \code{binary} or
\code{si} for ISI metric units).
}
\description{
Bytes formatter: convert to byte measurement and display symbol.
}
\examples{
byte_format()(sample(3000000000, 10))
bytes(sample(3000000000, 10))
}
\references{
Units of Information (Wikipedia) :
\url{http://en.wikipedia.org/wiki/Units_of_information}
}
Loading…
Cancel
Save