Description Usage Arguments Details Author(s) See Also Examples
This package provides a number of utility functions useful for manipulating large histograms. It provides a ‘HistogramTools.HistogramState’ protocol buffer representation of the default R histogram class to allow histograms to be very concisely serialized and shared with other systems in a distributed MapReduce environment. It also includes a number of utility functions for manipulating large histograms.
1 2 | ## S3 method for class 'Message'
as.histogram(x, ...)
|
x |
An RProtoBuf Message of type "HistogramTools.HistogramState" to convert to a histogram object. |
... |
Not used. |
as.histogram
reads the provided Protocol Buffer
message and extracts the buckets and counts to populate into the
standard R histogram class which can be plotted.
Murray Stokely mstokely@google.com
histogramtools-package
,
as.Message
, and
RProtoBuf
.
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 | if(require(RProtoBuf)) {
library(HistogramTools)
tmp.hist <- hist(c(1,2,4,43,20,33,1,1,3), plot=FALSE)
# The default R serialization takes a fair number of bytes
length(serialize(tmp.hist, NULL))
# Convert to a protocol buffer representation.
hist.msg <- as.Message(tmp.hist)
# Which has an ASCII representation like this:
cat(as.character(hist.msg))
# Or can be serialized and shared with other tools much more
# succinctly than R's built-in serialization format.
length(hist.msg$serialize(NULL))
# And since this isn't even compressed, we can reduce it further
# with in-memory compression:
length(memCompress(hist.msg$serialize(NULL)))
# If we read in the raw.bytes from another tool
raw.bytes <- hist.msg$serialize(NULL)
# We can parse the raw bytes as a protocol buffer
new.hist.proto <- P("HistogramTools.HistogramState")$read(raw.bytes)
new.hist.proto
# Then convert back to a native R histogram.
new.hist <- as.histogram(new.hist.proto)
# The new histogram and the old are identical except for xname
}
|
Loading required package: RProtoBuf
breaks: 0
breaks: 10
breaks: 20
breaks: 30
breaks: 40
breaks: 50
counts: 6
counts: 1
counts: 0
counts: 1
counts: 1
name: "c(1, 2, 4, 43, 20, 33, 1, 1, 3)"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.