new.counter | R Documentation |
This constructor method creates an object that can count occurrences of different items. It allows importing and exporting of the counter status in string form.
new.counter()
The object has the following methods:
inc(id)
: Increase the counter for item with id
by 1.
add(id,x)
: Add x
occurrences for the item with id
.
get(id)
: Get the number of occurrences seen for item id
.
ls(id)
: List all counts for all items by id.
export(id)
: Exports the counter state to a string that can be saved or logged.
import.add(str)
Imports a previous counter state from the string str
and adds it to the current counts.
An object of type yogicounter
.
cn <- new.counter()
cn$inc("foo")
cn$inc("bar")
cn$add("foo",6)
cn$get("foo")
# 7
cn$ls()
# foo 7
# bar 1
cn$export()
# foo=7,bar=1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.